From bfe16a7c6d5de7b5c9a2b0333cbfc404cf20f638 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 10 May 2018 03:48:28 +0100 Subject: [PATCH] lib/lua/nb.lua --- lib/lua/nb.lua | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index 67cc0e52..dc515c6d 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -5,7 +5,8 @@ local nb = { dev = 1, } -if ngx.var.PRODUCTION == 'yes' then nb.dev = 0 end +if ngx and ngx.var.PRODUCTION == 'yes' 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) @@ -64,11 +65,9 @@ function nb:ngx_location_md(fheader,ffooter) -- Default first tld domain if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end - local header = nb:readall(fheader) - if header then template.render(header,vars) end + local ishtml = true -- content = '{(header.html)}{*markdown[[' .. content .. ']]*}{footer.html)}' - content = template.output(template.compile(content)(vars)) if string.match(file,'%.md$') then -- Markdown discount = require("discount") @@ -81,17 +80,21 @@ function nb:ngx_location_md(fheader,ffooter) content = content:gsub("(<" .. tag .. ">) +","%1") end - ngx.print(content) + -- ngx.print(content) + + elseif string.match(file,'%.html?$') then - else --if string.match(file,'%.html$') then - -- Html - -- template.render(content,vars) - ngx.print(content) + else + ishtml = false + end + if ishtml and file ~= fheader and file ~= ffooter then + local header = self:readall(fheader) + local footer = nb:readall(ffooter) + content = header .. content .. footer end - local footer = nb:readall(ffooter) - if footer then template.render(footer,vars) end + template.render(content,vars) ngx.exit(0) end -- 2.47.3