From 21e924d8682e0e313ff9504839a1045d1b38e48f Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 30 Apr 2018 03:18:58 +0100 Subject: [PATCH] lib/lua/nb.lua --- lib/lua/nb.lua | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index efc88a44..148e632a 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -20,26 +20,32 @@ function nb:_ngx_location_md() 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, @@ -48,4 +54,5 @@ function nb:ngx_vars() geoip_latitude = ngx.var.geoip_latitude, geoip_longitude = ngx.var.geoip_longitude, } + return vars end -- 2.47.3