From: Nicolas Boisselier Date: Wed, 16 May 2018 13:01:02 +0000 (+0100) Subject: lib/lua/nb.lua X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=3c341053a6348a39c14291b701266f90f68cde54;p=nb.git lib/lua/nb.lua --- diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index 4c463b04..cb5cae6c 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -17,14 +17,15 @@ function nb:readall(file) end end -function nb:_ngx_location_md() - return +function nb:ngx_tmpl(content,fheader,ffooter) + ngx.ctx.tmpl_content = content + self:ngx_location_tmpl(fheader,ffooter) end -function nb:ngx_location_md(fheader,ffooter) +function nb:ngx_location_tmpl(fheader,ffooter) -- See https://github.com/bungle/lua-resty-template -- location ~ \.(md|html)$ { --- content_by_lua 'package.path = ngx.var.NB_ROOT .. "/lib/lua/?.lua;" .. package.path local nb = require("nb") 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_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 @@ -35,6 +36,7 @@ function nb:ngx_location_md(fheader,ffooter) local file = ngx.var.document_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 vars = {} @@ -84,7 +86,7 @@ function nb:ngx_location_md(fheader,ffooter) elseif string.match(file,'%.html?$') then - else + elseif not ngx.ctx.tmpl_content then ishtml = false end