1 | -- resty-gitweb@pages/index.lua |
2 | -- Index (home) page builder |
3 |
|
4 | -- Copyright (c) 2020 Joshua 'joshuas3' Stockin |
5 | -- <https://git.joshstock.in/resty-gitweb> |
6 | -- This software is licensed under the MIT License. |
7 |
|
8 | local utils = require("utils/utils") |
9 | local git = require("git/git") |
10 |
|
11 | local builder = require("utils/builder") |
12 | local tabulate = require("utils/tabulate") |
13 | local nav = require("utils/nav") |
14 |
|
15 | local _M = function(repos) |
16 | local build = builder:new() |
17 |
|
18 | build:add("<center class=\"home-banner\">") |
19 | build:add("<h1>Git Repositories</h1>") |
20 | build:add("<p>Index of the git repositories hosted on this server</p>") |
21 | build:add("</center>") |
22 |
|
23 | build:add("<div class=\"index-repolist\">") |
24 | local repo_sections = {} |
25 | for _, repo in pairs(repos) do |
26 | local section = builder:new() |
27 |
|
28 | local url = "/"..repo.name |
29 | local repo_dir = repo.location.dev |
30 |
|
31 | -- Title and description |
32 | section:add([[<div class="repo-section">]]) |
33 | section:add(string.format([[<h2 class="name">%s <a href="/%s" style="font-size:0.65em">[more]</a></h2>]], repo.name, repo.name)) |
34 | section:add([[<p class="description">]]..repo.description.."</p>") |
35 |
|
36 | -- Latest Commit table |
37 | local branch = git.get_head(repo_dir) |
38 | local commit = git.commit(repo_dir, branch.name) |
39 |
|
40 | section:add(string.format("<h3>Latest Commit (%s)</h3>", branch.name)) |
41 |
|
42 | local commits_table_data = {} |
43 | commits_table_data.class = "log" |
44 | commits_table_data.headers = { |
45 | {"count", [[<span class="q" title="Commit number/count">{#}</span>]]}, |
46 | {"timestamp", "Time"}, |
47 | {"shorthash", "Hash"}, |
48 | {"subject", "Subject"}, |
49 | {"author", "Author"}, |
50 | {"changed_files", [[<span class="q" title="# of files changed">#</span>]]}, |
51 | {"changed_plus", [[<span class="q" title="Insertions">(+)</span>]]}, |
52 | {"changed_minus", [[<span class="q" title="Deletions">(-)</span>]]}, |
53 | {"gpggood", [[<span class="q" title="GPG signature status |
54 | |
55 | G: Good (valid) signature |
56 | B: Bad signature |
57 | U: Good signature with unknown validity |
58 | X: Good signature that has expired |
59 | Y: Good signature made by an expired key |
60 | R: Good signature made by a revoked key |
61 | E: Signature can't be checked (e.g. missing key) |
62 | N: No signature">GPG?</span>]]} |
63 | } |
64 | commits_table_data.rows = {{ |
65 | commit.count, |
66 | utils.iso8601(commit.timestamp), |
67 | string.format([[<a href="/%s/commit/%s">%s</a>]], repo.name, commit.hash, commit.shorthash), |
68 | utils.html_sanitize(commit.subject), |
69 | string.format([[<a href="mailto:%s">%s</a>]], commit.email, utils.html_sanitize(commit.author)), |
70 | commit.diff.num, |
71 | commit.diff.plus, |
72 | commit.diff.minus, |
73 | commit.gpggood |
74 | }} |
75 |
|
76 | section:add(tabulate(commits_table_data)) |
77 |
|
78 | -- Navigation links |
79 | local navlinks = { |
80 | {string.format("/%s/download", repo.name), "Download"}, |
81 | {string.format("/%s/refs", repo.name), "Refs"}, |
82 | {string.format("/%s/log/%s", repo.name, branch.name), "Commit Log"}, |
83 | {string.format("/%s/tree/%s", repo.name, branch.name), "Files"} |
84 | } |
85 |
|
86 | for _, special in pairs(repo.specialfiles) do -- create nav items for special files |
87 | local split = string.split(special, " ") |
88 | table.insert(navlinks, { |
89 | string.format("/%s/blob/%s/%s", repo.name, branch.name, split[2]), |
90 | split[1] |
91 | }) |
92 | end |
93 |
|
94 | section:add([[<div class="nav">]]) |
95 | section:add(nav(navlinks)) |
96 |
|
97 | local gitlab_url = string.split(repo.urls[3], " ")[2] |
98 | local github_url = string.split(repo.urls[2], " ")[2] |
99 | section:add(string.format([[<span style="float:right"><a href="%s">[on GitLab]</a></span>]], gitlab_url)) |
100 | section:add(string.format([[<span style="float:right;margin-right:10px"><a href="%s">[on GitHub]</a></span>]], github_url)) |
101 |
|
102 | section:add("</div>") -- nav |
103 |
|
104 | section:add("</div>") -- repo-section |
105 |
|
106 | table.insert(repo_sections, section.body) |
107 | end |
108 |
|
109 | -- Format repo sections |
110 | build:add(table.concat(repo_sections, "<hr>")) |
111 |
|
112 | build:add("</div>") |
113 |
|
114 | return build |
115 | end |
116 |
|
117 | return _M |
118 |
|