]> git.nbdom.net Git - nb.git/commitdiff
lib/lua/nb.lua
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 30 Apr 2018 02:18:58 +0000 (03:18 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 30 Apr 2018 02:18:58 +0000 (03:18 +0100)
lib/lua/nb.lua

index efc88a44266735f9b056d177d86c5138f78fff06..148e632ac2e39934be84e5a52b9dd44cebc11597 100644 (file)
@@ -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