]> git.nbdom.net Git - nb.git/commitdiff
lib/lua/nb.lua
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 18 Sep 2018 21:31:21 +0000 (22:31 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 18 Sep 2018 21:31:21 +0000 (22:31 +0100)
lib/lua/nb.lua

index 1f1d52d2c71d79d01f50cde67d56a56b78a894dd..a8d1c6c0ce476c147b0c8c6d61357b5ae848db51 100644 (file)
@@ -106,12 +106,18 @@ function nb:ngx_location_tmpl(fheader,ffooter)
        if ngx.ctx.tmpl_content then content = ngx.ctx.tmpl_content end
        if not content then return end
 
-       local ishtml = true
-       if ngx.ctx.tmpl_content then
-               ishtml = false
+       local ishtml = false
+
+       if string.match(file,'%.html?$') then
+               ishtml = true
+
        elseif string.match(file,'%.md$') then
                content = self:md2html(content)
-       else
+
+       end
+
+       if ngx.ctx.tmpl_content then
+               ishtml = false
        end
 
        --
@@ -156,8 +162,7 @@ function nb:ngx_location_tmpl(fheader,ffooter)
        -- Header and footer
        if not fheader then fheader = root .. "/tmpl/header.tmpl.html" end
        if not ffooter then ffooter = root .. "/tmpl/footer.tmpl.html" end
-       --local header
-       --local footer
+
        if ishtml and file ~= fheader and file ~= ffooter and not string.match(file,'/tmpl/') then
                local header = self:readall(fheader)
                local footer = self:readall(ffooter)
@@ -168,9 +173,11 @@ function nb:ngx_location_tmpl(fheader,ffooter)
        -- Markdown includes
        local ptn = '%{%(([^%(%)]+%.md)%)%}'
        while true do
+
                local p1,p2,inc = content:find(ptn)
                if p1 == nil then break end
                local inc_content = self:readall(root .. '/' .. inc)
+
                if ishtml then
                        inc_content = self:md2html(inc_content)
                        inc_content = inc_content:gsub('^%s*<p>%s*',''):gsub('%s*</p>%s*$','')
@@ -184,11 +191,14 @@ function nb:ngx_location_tmpl(fheader,ffooter)
                                .. '>' .. inc_content .. '</div>'
                        end
                end
+
                content = ''
                        .. content:sub(0,p1-1)
                        .. inc_content
                        .. (content:sub(p2+1))
+
        end
+
        content = self:html_fix(content)
 
        -- See: /usr/local/share/lua/5.1/resty/template.lua