function nb:ngx_location_md()
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()
+ local vars = {}
-- Extract title from content or filename or dirname
vars.title = string.match(content,'^#[\t ]*([^\r\n]+)')
if not vars.title then
local head = nb:readall(ngx.var.document_root .. "/head.html")
if head then template.render(head,vars) end
+ content = template.output(template.compile(content)(vars))
if string.match(file,'%.md$') then
- -- First replace tags then md render
- content = template.output(template.compile(content)(vars))
- template.render("{*markdown[[" .. content .. "]]*}",vars)
+ -- Markdown
+ discount = require("discount")
+ ngx.print(discount(content))
+
+ elseif string.match(file,'%.html$') then
+ -- Html
+ -- template.render(content,vars)
+ ngx.print(content)
+
end
local tail = nb:readall(ngx.var.document_root .. "/tail.html")
ngx.exit(0)
end
-function nb:ngx_vars()
- 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_city = ngx.var.geoip_city,
- geoip_postal_code = ngx.var.geoip_postal_code,
- geoip_latitude = ngx.var.geoip_latitude,
- geoip_longitude = ngx.var.geoip_longitude,
- remote_addr = ngx.var.remote_addr,
- http_user_agent = ngx.var.http_user_agent,
- }
- return vars
-end
+-- function nb:ngx_vars()
+-- 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_city = ngx.var.geoip_city,
+-- geoip_postal_code = ngx.var.geoip_postal_code,
+-- geoip_latitude = ngx.var.geoip_latitude,
+-- geoip_longitude = ngx.var.geoip_longitude,
+-- remote_addr = ngx.var.remote_addr,
+-- http_user_agent = ngx.var.http_user_agent,
+-- }
+-- return vars
+-- end