-- NB 30.04.18:
-- See https://github.com/openresty/lua-nginx-module/blob/master/README.markdown
-- ngx.header["Content-type"] = "text/plain"
-nb = {
+local nb = {
dev = 1,
}
+if ngx.var.PRODUCTION then nb.dev = 0 end
function nb:readall(file)
-- local f = io.open(file) or error("Could not open file: " .. file)
local f = io.open(file)
function nb:ngx_location_md(fheader,ffooter)
-- location ~ \.(md|html)$ {
-- default_type text/html;
--- content_by_lua 'dofile(ngx.var.NB_ROOT .. "/lib/lua/nb.lua") nb:ngx_location_md()';
+-- content_by_lua 'package.path = ngx.var.NB_ROOT .. "/lib/lua/?.lua;" .. package.path local nb = require("nb") nb:ngx_location_md()';
-- }
if not fheader then fheader = ngx.var.document_root .. "/header.html" end
if not ffooter then ffooter = ngx.var.document_root .. "/footer.html" end
-- Markdown
discount = require("discount")
content = discount(content)
- local tags = { 'th', 'td' }
- -- for tag in self:values(tags) do
- -- content = content:gsub(" +(</th>)","%1")
- -- end
+
-- Fix markdown module
- content = content:gsub(" +(</th>)","%1")
- content = content:gsub("(<th>) +","%1")
- content = content:gsub(" +(</td>)","%1")
- content = content:gsub("(<td>) +","%1")
+ local tags = { 'th', 'td' }
+ for tag in self:values(tags) do
+ content = content:gsub(" +(</" .. tag .. ">)","%1")
+ content = content:gsub("(<" .. tag .. ">) +","%1")
+ end
+
ngx.print(content)
elseif string.match(file,'%.html$') then
ngx.exit(0)
end
-function readcmd(cmd)
- local f = assert(io.popen(cmd, 'r'))
- local s = assert(f:read('*a'))
- f:close()
- return s
-end
-
-function values(t)
+function nb:values(t)
local i = 0
return function() i = i + 1; return t[i] end
end
-- }
-- return vars
-- end
+
+function nb:readcmd(cmd)
+ local f = assert(io.popen(cmd, 'r'))
+ local s = assert(f:read('*a'))
+ f:close()
+ return s
+end
+
+function nb:ngx_cmd(cmd)
+ ngx.say(self:readcmd(cmd))
+ return 0
+end
+
+return nb