]> git.nbdom.net Git - nb.git/commitdiff
lib/lua/nb.lua
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 2 Jun 2018 13:05:10 +0000 (14:05 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 2 Jun 2018 13:05:10 +0000 (14:05 +0100)
lib/lua/nb.lua

index 2e3ed8269627a602238b054761f1a83ae38ca3aa..d8187e37bdda556b500e64f1d16205ecfcf0560d 100644 (file)
@@ -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,'<title[^>]*>(.*)</title>',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('<p><div','<div')
        content = content:gsub('div></p>','div>')
        content = content:gsub('[%s]*<tr>[%s]*<th>[%s]*</th>[%s]*<th>[%s]*</th>[%s]*</tr>[%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 = '<div class="md">' .. content .. '</div>'
        end