-- location ~ \.(md|html)$ {
-- content_by_lua_block { package.path = ngx.var.NB_ROOT .. "/lib/lua/?.lua;" .. package.path local nb = require("nb") nb:ngx_location_tmpl() }
-- }
- if not fheader then fheader = ngx.var.document_root .. "/header.html" end
- if not ffooter then ffooter = ngx.var.document_root .. "/footer.html" end
+ local root = ngx.var.document_root
+ if not fheader then fheader = root .. "/header.html" end
+ if not ffooter then ffooter = root .. "/footer.html" end
local template = require "resty.template"
- -- template.markdown = require "resty.hoedown"
if self.dev then template.caching(false) end
- local file = ngx.var.document_root .. ngx.var.uri;
+ local file = root .. ngx.var.uri;
local content = self:readall(file)
if ngx.ctx.tmpl_content then content = ngx.ctx.tmpl_content end
if not content then return end
local ishtml = true
- -- content = '{(header.html)}{*markdown[[' .. content .. ']]*}{footer.html)}'
- if string.match(file,'%.md$') then
+ local discount = require("discount")
+ if false then
+ template.markdown = require "resty.hoedown"
+ -- ngx.say('zaza' .. template.markdown.html.flags.table)
+ --content = discount(content)
+ content = '{(header.html)}{*markdown([[' .. content .. ']], { smartypants = false, table = true })*}{(footer.html)}'
+ -- content = discount(content)
+ ishtml = false
+ elseif string.match(file,'%.md$') then
-- Markdown
- discount = require("discount")
content = discount(content)
-- Fix markdown module
if ishtml and file ~= fheader and file ~= ffooter then
local header = self:readall(fheader)
- local footer = nb:readall(ffooter)
+ local footer = self:readall(ffooter)
content = header .. content .. footer
ngx.header["Content-type"] = "text/html"
end
+ local ptn = '%{%(([^%(%)]+%.md)%)%}'
+ while true do
+ local p1,p2,inc = content:find(ptn)
+ if p1 == nil then break end
+ inc = self:readall(root .. '/' .. inc)
+ if ishtml then inc = discount(inc) end
+ content = ''
+ .. content:sub(0,p1-1)
+ .. inc
+ .. (content:sub(p2+1))
+ end
+
template.render(content,vars)
ngx.exit(0)
end
function nb:values(t)
- local i = 0
- return function() i = i + 1; return t[i] end
+ local i = 0
+ return function() i = i + 1; return t[i] end
end
-- function nb:ngx_vars()
-- local vars = {}
end
function nb:script_path()
- local str = debug.getinfo(2, "S").source:sub(2)
- return str:match("(.*)/")
+ local str = debug.getinfo(2, "S").source:sub(2)
+ return str:match("(.*)/")
end
return nb