Index

resty-gitweb / c69d6c0

A git web interface for Lua/OpenResty (you're on it right now!)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
703 Jan 2021 10:11609d330libgit2 binding updates, README updatesJosh Stockin111G

Blob @ resty-gitweb / pages / index.lua

text/plain4347 bytesdownload raw
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
8local utils = require("utils/utils")
9local git = require("git/git")
10
11local builder = require("utils/builder")
12local tabulate = require("utils/tabulate")
13local nav = require("utils/nav")
14
15local _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
55G: Good (valid) signature
56B: Bad signature
57U: Good signature with unknown validity
58X: Good signature that has expired
59Y: Good signature made by an expired key
60R: Good signature made by a revoked key
61E: Signature can't be checked (e.g. missing key)
62N: 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
115end
116
117return _M
118