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
--
-- 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)
-- 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*$','')
.. '>' .. 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