]> git.nbdom.net Git - nb.git/commitdiff
lib/lua/nb.lua
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 10 May 2018 02:48:28 +0000 (03:48 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 10 May 2018 02:48:28 +0000 (03:48 +0100)
lib/lua/nb.lua

index 67cc0e52a55984cb2da457c97793695bf0f2bcd6..dc515c6ddc0c013882bdd01946e1e7ccdf9bc45f 100644 (file)
@@ -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