From c2328f3ddceadeae3f1749f4dee9d894fc932ec7 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sat, 2 Jun 2018 14:05:10 +0100 Subject: [PATCH] lib/lua/nb.lua --- lib/lua/nb.lua | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index 2e3ed826..d8187e37 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -5,7 +5,7 @@ local nb = { dev = 1, } -local discount = nil +local md2html_discount = nil if ngx and ngx.var.PRODUCTION == 'yes' then nb.dev = 0 end @@ -24,7 +24,7 @@ function nb:ngx_tmpl_file(file,fheader,ffooter) self:ngx_location_tmpl(fheader,ffooter) end -function nb:ngx_tmpl(content,fheader,ffooter) +function nb:ngx_tmpl_content(content,fheader,ffooter) ngx.ctx.tmpl_content = content self:ngx_location_tmpl(fheader,ffooter) end @@ -35,9 +35,11 @@ function nb:ngx_location_tmpl(fheader,ffooter) -- content_by_lua_block { package.path = ngx.var.NB_ROOT .. "/lib/lua/?.lua;" .. package.path local nb = require("nb") nb:ngx_location_tmpl() } -- } local root = ngx.var.document_root - local file = root .. ngx.var.uri; +-- NB 02.06.18 local file = root .. ngx.var.uri; + local file = ngx.var.request_filename; local path = file:gsub('/[^/]+$','') - local vars = {} + local vars = { + } if not fheader then fheader = root .. "/header.tmpl.html" end if not ffooter then ffooter = root .. "/footer.tmpl.html" end @@ -80,6 +82,7 @@ function nb:ngx_location_tmpl(fheader,ffooter) elseif not ngx.ctx.tmpl_content then ishtml = false + if not vars.title then vars.title = string.match(content,']*>(.*)',1) end end -- Header and footer @@ -178,10 +181,12 @@ function nb:script_path() return str:match("(.*)/") end -function nb:filepath2name(inc) - local name = inc +-- function nb.filepath2name(filepath) return nb:gsub(filepath) end +function nb:filepath2name(filepath) + local name = filepath name = name:gsub('%.[^/]+$','') name = name:gsub('/index$','') + name = name:gsub('^[^%w]+',''):gsub('[^%w]+$','') name = name:gsub('[^%w]+','-') return name end @@ -198,12 +203,16 @@ function nb:html_fix(content) content = content:gsub('

','div>') content = content:gsub('[%s]*[%s]*[%s]*[%s]*[%s]*[%s]*[%s]*','') + + -- xHtml + content = content:gsub('<(hr)>','<%1/>') + return content end function nb:md2html(content) - if self.discount == nil then self.discount = require("discount") end - content = self.discount(content) + if self.md2html_discount == nil then self.md2html_discount = require("discount") end + content = self.md2html_discount(content) if content then content = '
' .. content .. '
' end -- 2.47.3