local vars = {
path_file = path,
path_uri = ngx.var.request_uri:gsub('?.*$',''),
+ --body_id = ngx.var.request_uri:gsub('%.%w+',''):gsub('[^%w]+','-'):gsub('^-+',''):gsub('-+$',''),
}
+ --if vars.body_id == '' then vars.body_id='index' end
if not fheader then fheader = root .. "/tmpl/header.tmpl.html" end
if not ffooter then ffooter = root .. "/tmpl/footer.tmpl.html" end
local template = require "resty.template"
+ local context
-- NB 25.05.18 template.print = function(s)
-- NB 25.05.18 ngx.print(s)
-- NB 25.05.18 end
end
local ishtml = true
-
- if false and string.match(file,'%.md$') then
- template.markdown = require "resty.hoedown"
- -- ngx.say('zaza' .. template.markdown.html.flags.table)
- --content = self:md2html(content)
- content = '{(header.html)}{*markdown([[' .. content .. ']], { smartypants = false, table = true })*}{(footer.html)}'
- -- content = self:md2html(content)
+ if ngx.ctx.tmpl_content then
ishtml = false
elseif string.match(file,'%.md$') then
- -- Extract title from h1
- if not vars.title then vars.title = string.match(content,'^#[\t ]*([^\r\n]+)',1) end
- -- Extract title from h2
- if not vars.title then vars.title = string.match(content,'##[\t ]*([^\r\n]+)',1) end
-
- -- Markdown
content = self:md2html(content)
-
- elseif string.match(file,'%.html?$') then
- local i = '<[^>]+>'
- -- Extract title from h1
- if not vars.title then vars.title = string.match(content:gsub('(<h1[^>]*>)<[^>]+>','%1'),'<h1[^>]*>([^<>]+)',1) end
- -- Extract title from h2
- if not vars.title then vars.title = string.match(content:gsub('(<h2[^>]*>)<[^>]+>','%1'),'<h2[^>]*>([^<>]+)',1) end
-
- elseif not ngx.ctx.tmpl_content then
- ishtml = false
- if not vars.title then vars.title = string.match(content,'<title[^>]*>([^>]+)</title>',1) end
+ else
end
-- Header and footer
.. inc_content
.. (content:sub(p2+1))
end
+ content = self:html_fix(content)
+
+ --
+ -- Get title
+ --
+ content = template.compile(content,vars)(context)
+
+ -- Extract title from h1
+ if not vars.title then
+ vars.title = string.match(content:gsub('(<h1[^>]*>)<[^>]+>','%1'),'<h1[^>]*>([^<>]+)',1)
+ end
+
+ -- Extract title from h2
+ if not vars.title then
+ vars.title = string.match(content:gsub('(<h2[^>]*>)<[^>]+>','%1'),'<h2[^>]*>([^<>]+)',1)
+ end
-- From request_uri
if not vars.title then
-- Default first tld domain
-- if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end
- content = self:html_fix(content)
-
-- See: /usr/local/share/lua/5.1/resty/template.lua
-- Same as: template.print(template.compile(content,vars)(context))
template.render(content,vars)