Index

joshstock.in / 8147f6b

Source for serving and static templating/compiling of https://joshstock.in.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
9712 Dec 2020 21:058147f6bUpdate lua-gitwebJosh Stockin155G

Blob @ joshstock.in / lua-gitweb / pages / index.lua

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