--- /dev/null
+-- NB 30.04.18:
+-- See https://github.com/openresty/lua-nginx-module/blob/master/README.markdown
+-- ngx.header["Content-type"] = "text/plain"
+nb = {
+ dev = 1,
+}
+
+function nb:readall(file)
+ -- local f = io.open(file) or error("Could not open file: " .. file)
+ local f = io.open(file)
+ if f then
+ local content = f:read("*all")
+ f:close()
+ return content
+ end
+end
+
+function nb:_ngx_location_md()
+ return
+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 head = nb:readall(ngx.var.document_root .. "/head.html")
+ if head then ngx.print(head) end
+
+ template.render("{*markdown[[" .. content .. " ]]*}",self:ngx_vars())
+
+ local tail = nb:readall(ngx.var.document_root .. "/tail.html")
+ if tail then ngx.print(tail) end
+
+ ngx.exit(0)
+end
+
+function nb:ngx_vars()
+ return {
+ 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,
+ }
+end