Index

resty-gitweb / 113602d

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1123 Jan 2021 10:52113602dMore code updatesJosh Stockin195G

Blob @ resty-gitweb / pages / index.lua

text/plain4378 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 exists, repo_obj = git.repo.open(repo_dir)
38 local branch = git.find_rev(repo_obj, "HEAD")
39 git.repo.free(repo_obj)
40 local commit = git.commit(repo_dir, branch.name)
41
42 section:add(string.format("<h3>Latest Commit (%s)</h3>", branch.name))
43
44 local commits_table_data = {}
45 commits_table_data.class = "log"
46 commits_table_data.headers = {
47 {"count", [[<span class="q" title="Commit number/count">{#}</span>]]},
48 {"timestamp", "Time"},
49 {"shorthash", "Hash"},
50 {"subject", "Subject"},
51 {"author", "Author"},
52 {"changed_files", [[<span class="q" title="# of files changed">#</span>]]},
53 {"changed_plus", [[<span class="q" title="Insertions">(+)</span>]]},
54 {"changed_minus", [[<span class="q" title="Deletions">(-)</span>]]},
55 {"gpggood", [[<span class="q" title="GPG signature status
56
57G: Good (valid) signature
58B: Bad signature
59U: Good signature with unknown validity
60X: Good signature that has expired
61Y: Good signature made by an expired key
62R: Good signature made by a revoked key
63E: Signature can't be checked (e.g. missing key)
64N: No signature">GPG?</span>]]}
65 }
66 commits_table_data.rows = {{
67 commit.count,
68 utils.iso8601(commit.timestamp),
69 string.format([[<a href="/%s/commit/%s">%s</a>]], repo.name, commit.hash, commit.shorthash),
70 utils.html_sanitize(commit.subject),
71 string.format([[<a href="mailto:%s">%s</a>]], commit.email, utils.html_sanitize(commit.author)),
72 commit.diff.num,
73 commit.diff.plus,
74 commit.diff.minus,
75 commit.gpggood
76 }}
77
78 section:add(tabulate(commits_table_data))
79
80 -- Navigation links
81 local navlinks = {
82 {string.format("/%s/download", repo.name), "Download"},
83 {string.format("/%s/refs", repo.name), "Refs"},
84 {string.format("/%s/log/%s", repo.name, branch.name), "Commit Log"},
85 {string.format("/%s/tree/%s", repo.name, branch.name), "Files"}
86 }
87
88 for _, special in pairs(repo.specialfiles) do -- create nav items for special files
89 local split = string.split(special, " ")
90 table.insert(navlinks, {
91 string.format("/%s/blob/%s/%s", repo.name, branch.name, split[2]),
92 split[1]
93 })
94 end
95
96 section:add([[<div class="nav">]])
97 section:add(nav(navlinks))
98
99 for i = #repo.urls, 1, -1 do
100 local split = string.split(repo.urls[i], " ")
101 local name = split[1]
102 local url = split[2]
103 section:add(string.format([[<span style="float:right;margin-left:10px"><a href="%s">[on %s]</a></span>]], url, name))
104 end
105
106 section:add("</div>") -- nav
107
108 section:add("</div>") -- repo-section
109
110 table.insert(repo_sections, section.body)
111 end
112
113 -- Format repo sections
114 build:add(table.concat(repo_sections, "<hr>"))
115
116 build:add("</div>")
117
118 return build
119end
120
121return _M
122