Index

joshstock.in / 8d4dd89

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
9301 Dec 2020 20:568d4dd89Create basic layout for lua-gitwebJosh Stockin17121G

Blob @ joshstock.in / lua-gitweb / app.lua

text/plain3251 bytesdownload raw
1local utils = require("utils")
2local git = require("git_commands")
3
4ngx.say("<style>body{width:1100px;margin:20px auto;font-family:sans-serif}img{max-width:100%}pre{background-color:#eee;padding:8px;overflow-x:auto}:not(pre)>code{background-color:#eee;padding:2px}td,th{padding:2px 5px;border:1px solid #858585;text-align:left;vertical-align:top}table{border-collapse:collapse;font-family:monospace;width:100%}td:not(:nth-child(3)){width:1%;white-space:nowrap}.readme{padding:20px 50px;border:1px solid #ccc}</style>")
5ngx.say("<body>")
6
7local md2html = function(file)
8 local formatted_command = string.format(
9 "/usr/local/bin/md2html --github %s",
10 file
11 )
12 return utils.process(formatted_command)
13end
14
15print_table = function(t, l)
16 l = l or 0
17 local n = 0
18 for i,v in pairs(t) do n = n + 1 break end
19 if n > 0 then
20 ngx.print("{\n")
21 for i,v in pairs(t) do
22 for i=0,l do ngx.print(" ") end
23 ngx.print("<span style='color:red'>",i,": </span>")
24 if type(v) ~= "table" then
25 if type(v) == "string" then
26 ngx.print("\"")
27 local s = v:gsub("&", "&amp;"):gsub("<","&lt;"):gsub(">","&gt;")
28 ngx.print(s)
29 ngx.print("\"")
30 else
31 ngx.print(v)
32 end
33 else
34 print_table(v,l+1)
35 end
36 ngx.print("\n")
37 end
38 for i=0,l-1 do ngx.print(" ") end
39 ngx.print("}")
40 else
41 ngx.print("{}")
42 end
43end
44
45local name = "ncurses-minesweeper"
46--local name = "lognestmonster"
47--local name = "auto-plow"
48--local name = "joshstock.in"
49local repo = "/home/josh/repos/"..name
50local commits_head = git.log(repo, "@", 10, 0, true)
51
52ngx.say("<h2>"..name.." / master</h2>")
53ngx.say("<p>Terminal game of Minesweeper, implemented in C with ncurses.</p>")
54ngx.say("<p>Log | Files | Refs | README | LICENSE</p>")
55ngx.say("<table>")
56ngx.print("<tr>")
57ngx.print("<th>Date</th>")
58ngx.print("<th>Hash</th>")
59ngx.print("<th>Subject</th>")
60ngx.print("<th>Author</th>")
61ngx.print("<th>Email</th>")
62ngx.print("<th>+</th>")
63ngx.print("<th>-</th>")
64ngx.print("<th>GPG?</th>")
65ngx.print("<tr>")
66for i,commit in pairs(commits_head) do
67 ngx.print("<tr>")
68 ngx.print("<td>",utils.iso8601(commit.timestamp),"</td>")
69 ngx.print("<td><a href=\"/"..name.."/commit/",commit.hash,"\">",commit.shorthash,"</a></td>")
70 ngx.print("<td>",commit.subject,"</td>")
71 ngx.print("<td>",commit.author,"</td>")
72 ngx.print("<td><a href=\"mailto:",commit.email,"\">",commit.email,"</a></td>")
73 ngx.print("<td style=\"color:",commit.diff.plus>commit.diff.minus and "green;font-weight:bold" or "inherit","\">",commit.diff.plus,"</td>")
74 ngx.print("<td style=\"color:",commit.diff.minus>commit.diff.plus and "red;font-weight:bold" or "inherit","\">",commit.diff.minus,"</td>")
75 ngx.print("<td><b style=\"color:", commit.gpggood=="G" and "green" or "red","\">",commit.gpggood,"</b></td>")
76 ngx.say("</tr>")
77end
78ngx.say("</table>")
79
80ngx.say("<div class=\"readme\">")
81ngx.say("<h5>README</h5>")
82ngx.say(md2html(repo.."/README.md"))
83ngx.say("</div>")
84
85ngx.say("</body>")
86
87ngx.exit(ngx.HTTP_OK)
88