1 | local utils = require("utils") |
2 |
|
3 | ngx.say("<body style=\"max-width:800px;margin:0 auto;overflow:wrap;\">") |
4 |
|
5 | local function script_path() |
6 | return debug.getinfo(2, "S").source:sub(2):match("(.*/)") |
7 | end |
8 |
|
9 | local 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 |
26 | end |
27 |
|
28 | ngx.say("<pre><code>") |
29 | ngx.say(ngx.req.raw_header()) |
30 | ngx.say("</code></pre>") |
31 |
|
32 | local readme = script_path().."README.md" |
33 | ngx.say(md2html(readme)) |
34 |
|
35 | ngx.say("</body>") |
36 |
|
37 | ngx.exit(ngx.HTTP_OK) |
38 |
|