From: Nicolas Boisselier Date: Mon, 30 Apr 2018 17:32:28 +0000 (+0100) Subject: lib/lua/nb.lua X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=8a140d1d31bc8026300efca5ee71ca0790e4bd7f;p=nb.git lib/lua/nb.lua --- diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index 5bf786a6..77a643bc 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -22,13 +22,12 @@ end 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 @@ -41,10 +40,17 @@ function nb:ngx_location_md() 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") @@ -53,18 +59,18 @@ function nb:ngx_location_md() 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