local root = ngx.var.document_root
local file = root .. ngx.var.uri;
local path = file:gsub('/[^/]+$','')
+ local vars = {}
if not fheader then fheader = root .. "/header.tmpl.html" end
if not ffooter then ffooter = root .. "/footer.tmpl.html" end
if ngx.ctx.tmpl_content then content = ngx.ctx.tmpl_content end
if not content then return end
- local vars = {}
- -- Extract title from h1
- vars.title = string.match(content,'^#[\t ]*([^\r\n]+)')
-
- if not vars.title then
- -- Extract title from h2
- vars.title = string.match(content,'##[\t ]*([^\r\n]+)')
- end
- -- From filename
--- if not vars.title then
--- vars.title = string.match(file,'([^/%.]+)%.') -- basename
--- if vars.title == 'index' then
--- vars.title = string.match(file,'/([^/]+)/[^/]+$')
--- end
--- end
-
- -- From request_uri
- if not vars.title then
- local basename = string.match(ngx.var.request_uri,'([^/]+)$')
- if basename then
- local noext = string.match(basename,'([^%.]+)')
- vars.title = noext
- end
- end
-
- -- Default first tld domain
- if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end
-
local ishtml = true
if false then
-- Markdown
content = self:md2html(content)
- -- ngx.print(content)
+ -- Extract title from h1
+ if not vars.title then vars.title = string.match(content,'^#[\t ]*([^\r\n]+)') end
+ -- Extract title from h2
+ if not vars.title then vars.title = string.match(content,'##[\t ]*([^\r\n]+)') end
+
elseif string.match(file,'%.html?$') then
+ -- Extract title from h1
+ if not vars.title then vars.title = string.match(content,'<h1[^>]*>(.*?)</h1>') end
+ -- Extract title from h2
+ if not vars.title then vars.title = string.match(content,'<h2[^>]*>(.*?)</h2>') end
elseif not ngx.ctx.tmpl_content then
ishtml = false
.. (content:sub(p2+1))
end
+ -- From filename
+-- if not vars.title then
+-- vars.title = string.match(file,'([^/%.]+)%.') -- basename
+-- if vars.title == 'index' then
+-- vars.title = string.match(file,'/([^/]+)/[^/]+$')
+-- end
+-- end
+
+ -- From request_uri
+ if not vars.title then
+ local basename = string.match(ngx.var.request_uri,'([^/]+)$')
+ if basename then
+ local noext = string.match(basename,'([^%.]+)')
+ vars.title = noext
+ end
+ end
+
+ -- Default first tld domain
+ if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end
+
content = self:html_fix(content)
template.render(content,vars)