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

index 5bf786a66cfc23595c9bf4d0392e5434d4604f69..77a643bc701673a8007930196bdf7d33ef543bb4 100644 (file)
@@ -22,13 +22,12 @@ end
 function nb:ngx_location_md()
 
        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()
+       local vars = {}
        -- Extract title from content or filename or dirname
        vars.title = string.match(content,'^#[\t ]*([^\r\n]+)')
        if not vars.title then
@@ -41,10 +40,17 @@ function nb:ngx_location_md()
        local head = nb:readall(ngx.var.document_root .. "/head.html")
        if head then template.render(head,vars) end
 
+       content = template.output(template.compile(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)
+               -- Markdown
+               discount = require("discount")
+               ngx.print(discount(content))
+
+       elseif string.match(file,'%.html$') then
+               -- Html
+               -- template.render(content,vars)
+               ngx.print(content)
+
        end
 
        local tail = nb:readall(ngx.var.document_root .. "/tail.html")
@@ -53,18 +59,18 @@ function nb:ngx_location_md()
        ngx.exit(0)
 end
 
-function nb:ngx_vars()
-       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,
-               geoip_city = ngx.var.geoip_city,
-               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
+-- function nb:ngx_vars()
+--     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,
+--             geoip_city = ngx.var.geoip_city,
+--             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