]> git.nbdom.net Git - nb.git/commitdiff
lib/lua/nb.lua
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 11 Jun 2018 12:15:08 +0000 (13:15 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 11 Jun 2018 12:15:08 +0000 (13:15 +0100)
lib/lua/nb.lua

index 7cc7483dfdd310080eb70fa9c2f93316460d5a0b..0fa6248712c4d8697de7b868b067de6d116e968a 100644 (file)
@@ -54,10 +54,15 @@ function nb:ngx_location_tmpl(fheader,ffooter)
        local content = self:readall(file)
        if ngx.ctx.tmpl_content then content = ngx.ctx.tmpl_content end
        if not content then return end
+       if ngx.var.request_uri:match('^/dev/') then
+               --content = template.compile(content,vars)(context)
+               --ngx.print(content)
+               --return
+       end
 
        local ishtml = true
 
-       if false then
+       if false and string.match(file,'%.md$') then
                template.markdown = require "resty.hoedown"
                -- ngx.say('zaza' .. template.markdown.html.flags.table)
                --content = self:md2html(content)
@@ -76,9 +81,9 @@ function nb:ngx_location_tmpl(fheader,ffooter)
        elseif string.match(file,'%.html?$') then
                local i = '<[^>]+>'
                -- Extract title from h1
-               if not vars.title then vars.title = string.match(content,'<h1[^>]*>([^>]+)</h1>',1) end
+               if not vars.title then vars.title = string.match(content:gsub('(<h1[^>]*>)<[^>]+>','%1'),'<h1[^>]*>([^<>]+)',1) end
                -- Extract title from h2
-               if not vars.title then vars.title = string.match(content,'<h2[^>]*>([^>]+)</h2>',1) end
+               if not vars.title then vars.title = string.match(content:gsub('(<h2[^>]*>)<[^>]+>','%1'),'<h2[^>]*>([^<>]+)',1) end
 
        elseif not ngx.ctx.tmpl_content then
                ishtml = false