return
end
-function nb:ngx_location_md()
+function nb:ngx_location_md(fheader,ffooter)
-- location ~ \.(md|html)$ {
-- default_type text/html;
-- content_by_lua 'dofile(ngx.var.NB_ROOT .. "/lib/lua/nb.lua") nb:ngx_location_md()';
-- }
+ if not fheader then fheader = ngx.var.document_root .. "/header.html" end
+ if not ffooter then ffooter = ngx.var.document_root .. "/footer.html" end
local template = require "resty.template"
if self.dev then template.caching(false) end
local vars = {}
-- Extract title from content or filename or dirname
- --vars.title = string.match(content,'^#[\t ]*([^\r\n]+)')
+ vars.title = string.match(content,'^#[\t ]*([^\r\n]+)')
+
+ -- 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
vars.title = noext
end
end
+
+ -- Default first tld domain
if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end
- local header = nb:readall(ngx.var.document_root .. "/header.html")
+ local header = nb:readall(fheader)
if header then template.render(header,vars) end
content = template.output(template.compile(content)(vars))
end
- local footer = nb:readall(ngx.var.document_root .. "/footer.html")
+ local footer = nb:readall(ffooter)
if footer then template.render(footer,vars) end
ngx.exit(0)