From: Nicolas Boisselier Date: Tue, 18 Sep 2018 21:31:21 +0000 (+0100) Subject: lib/lua/nb.lua X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=82a8681331788be940337d61ccff05b46bb97566;p=nb.git lib/lua/nb.lua --- diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index 1f1d52d2..a8d1c6c0 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -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*

%s*',''):gsub('%s*

%s*$','') @@ -184,11 +191,14 @@ function nb:ngx_location_tmpl(fheader,ffooter) .. '>' .. inc_content .. '' 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