end
function nb:ngx_location_md()
- local file = ngx.var.document_root .. ngx.var.uri;
- local content = self:readall(file)
local template = require "resty.template"
template.markdown = require "resty.hoedown"
if self.dev then template.caching(false) end
+ local file = ngx.var.document_root .. ngx.var.uri;
+ local content = self:readall(file)
+
+ local vars = self:ngx_vars()
+ vars.title = string.match(content,'^#[\t ]*([^\r\n]+)')
+ -- if not vars.title then vars.title = string.match(file,'([^\.]+)\.') end
+
local head = nb:readall(ngx.var.document_root .. "/head.html")
- if head then ngx.print(head) end
+ if head then template.render(head,vars) end
- template.render("{*markdown[[" .. content .. " ]]*}",self:ngx_vars())
+ template.render("{*markdown[[" .. content .. " ]]*}",vars)
local tail = nb:readall(ngx.var.document_root .. "/tail.html")
- if tail then ngx.print(tail) end
+ if tail then template.render(tail,vars) end
ngx.exit(0)
end
function nb:ngx_vars()
- return {
+ local vars = {}
+ vars = {
geoip_city_continent_code = ngx.var.geoip_city_continent_code,
geoip_country_code = ngx.var.geoip_country_code,
geoip_country_name = ngx.var.geoip_country_name,
geoip_latitude = ngx.var.geoip_latitude,
geoip_longitude = ngx.var.geoip_longitude,
}
+ return vars
end