]> git.nbdom.net Git - nb.git/commitdiff
lib/lua/nb.lua
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 16 May 2018 13:01:02 +0000 (14:01 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 16 May 2018 13:01:02 +0000 (14:01 +0100)
lib/lua/nb.lua

index 4c463b043e1e6f964e4740c1329bb615baba5a7c..cb5cae6cec83ef5a06108710df14b4b0c5c54b07 100644 (file)
@@ -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