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

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