1 | local utils = require("utils") |
2 | local git = require("git_commands") |
3 |
|
4 | ngx.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>") |
5 | ngx.say("<body>") |
6 |
|
7 | local 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) |
13 | end |
14 |
|
15 | print_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("&", "&"):gsub("<","<"):gsub(">",">") |
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 |
43 | end |
44 |
|
45 | local name = "ncurses-minesweeper" |
46 | --local name = "lognestmonster" |
47 | --local name = "auto-plow" |
48 | --local name = "joshstock.in" |
49 | local repo = "/home/josh/repos/"..name |
50 | local commits_head = git.log(repo, "@", 10, 0, true) |
51 |
|
52 | ngx.say("<h2>"..name.." / master</h2>") |
53 | ngx.say("<p>Terminal game of Minesweeper, implemented in C with ncurses.</p>") |
54 | ngx.say("<p>Log | Files | Refs | README | LICENSE</p>") |
55 | ngx.say("<table>") |
56 | ngx.print("<tr>") |
57 | ngx.print("<th>Date</th>") |
58 | ngx.print("<th>Hash</th>") |
59 | ngx.print("<th>Subject</th>") |
60 | ngx.print("<th>Author</th>") |
61 | ngx.print("<th>Email</th>") |
62 | ngx.print("<th>+</th>") |
63 | ngx.print("<th>-</th>") |
64 | ngx.print("<th>GPG?</th>") |
65 | ngx.print("<tr>") |
66 | for 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>") |
77 | end |
78 | ngx.say("</table>") |
79 |
|
80 | ngx.say("<div class=\"readme\">") |
81 | ngx.say("<h5>README</h5>") |
82 | ngx.say(md2html(repo.."/README.md")) |
83 | ngx.say("</div>") |
84 |
|
85 | ngx.say("</body>") |
86 |
|
87 | ngx.exit(ngx.HTTP_OK) |
88 |
|