Index

joshstock.in / a871d4d

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
9130 Nov 2020 16:24a871d4dMove git-history/ to lua-gitweb/Josh Stockin1370G

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

text/plain890 bytesdownload raw
1local utils = require("utils")
2
3ngx.say("<body style=\"max-width:800px;margin:0 auto;overflow:wrap;\">")
4
5local function script_path()
6 return debug.getinfo(2, "S").source:sub(2):match("(.*/)")
7end
8
9local md2html = function(file)
10 local formatted_command = string.format(
11 "md2html --github %s",
12 file
13 )
14 local output
15 local status, err = pcall(function()
16 local process = io.popen(formatted_command, "r")
17 assert(process, "Error opening md2html process")
18 output = process:read("*a")
19 process:close()
20 end)
21 if status then
22 return output
23 else
24 return string.format("Error in md2html call: %s", err or "")
25 end
26end
27
28ngx.say("<pre><code>")
29ngx.say(ngx.req.raw_header())
30ngx.say("</code></pre>")
31
32local readme = script_path().."README.md"
33ngx.say(md2html(readme))
34
35ngx.say("</body>")
36
37ngx.exit(ngx.HTTP_OK)
38