From 8f9778334d12c3f3e6daac2eee2b47581f39e603 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 30 Apr 2018 13:43:03 +0100 Subject: [PATCH] lib/lua/nb.lua --- lib/lua/nb.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index 148e632a..5bf786a6 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -29,13 +29,23 @@ function nb:ngx_location_md() local content = self:readall(file) local vars = self:ngx_vars() + -- Extract title from content or filename or dirname vars.title = string.match(content,'^#[\t ]*([^\r\n]+)') - -- if not vars.title then vars.title = string.match(file,'([^\.]+)\.') end + if not vars.title then + vars.title = string.match(file,'([^/%.]+)%.') + if vars.title == 'index' then + vars.title = string.match(file,'/([^/]+)/[^/]+$') + end + end local head = nb:readall(ngx.var.document_root .. "/head.html") if head then template.render(head,vars) end - template.render("{*markdown[[" .. 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) + end local tail = nb:readall(ngx.var.document_root .. "/tail.html") if tail then template.render(tail,vars) end @@ -53,6 +63,8 @@ function nb:ngx_vars() 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 -- 2.47.3