]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d/functions
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 14 Jun 2018 01:09:35 +0000 (02:09 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 14 Jun 2018 01:09:35 +0000 (02:09 +0100)
etc/profile.d/functions
lib/lua/nb.lua

index 0279a551065300c90057074c211d5fe440622be1..c4abb4d0bc7a251603b1c3147ac27225c43d6b88 100755 (executable)
@@ -878,9 +878,9 @@ minify_dir() {
 
 html2txt() {
        if which lynx > /dev/null; then
-               lynx -pseudo_inlines -nomargins -display_charset=utf8 -nocolor -nolist -width=999999 -dump "$1"
+               lynx -pseudo_inlines -nomargins -display_charset=utf8 -nocolor -nolist -width=999999 -dump "${1:--stdin}"
        elif which w3m > /dev/null; then
-               w3m -dump -cols 999999 "$1"
+               w3m -dump -cols 999999 -T text/html "$1"
        else
                echo "Please install lynx or w3m" 1>&2
                return 1
index b05229a684a26c35530cd7c24d08652bce52fa49..62fea668d949d657a3e547c658eb8360160d64ff 100644 (file)
@@ -41,12 +41,15 @@ function nb:ngx_location_tmpl(fheader,ffooter)
        local vars = {
                path_file = path,
                path_uri = ngx.var.request_uri:gsub('?.*$',''),
+               --body_id = ngx.var.request_uri:gsub('%.%w+',''):gsub('[^%w]+','-'):gsub('^-+',''):gsub('-+$',''),
        }
+       --if vars.body_id == '' then vars.body_id='index' end
 
        if not fheader then fheader = root .. "/tmpl/header.tmpl.html" end
        if not ffooter then ffooter = root .. "/tmpl/footer.tmpl.html" end
 
        local template = require "resty.template"
+       local context
 -- NB 25.05.18         template.print = function(s)
 -- NB 25.05.18           ngx.print(s)
 -- NB 25.05.18         end
@@ -63,33 +66,11 @@ function nb:ngx_location_tmpl(fheader,ffooter)
        end
 
        local ishtml = true
-
-       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)
-               content = '{(header.html)}{*markdown([[' .. content .. ']], { smartypants = false, table = true })*}{(footer.html)}'
-               -- content = self:md2html(content)
+       if ngx.ctx.tmpl_content then
                ishtml = false
        elseif string.match(file,'%.md$') then
-               -- Extract title from h1
-               if not vars.title then vars.title = string.match(content,'^#[\t ]*([^\r\n]+)',1) end
-               -- Extract title from h2
-               if not vars.title then vars.title = string.match(content,'##[\t ]*([^\r\n]+)',1) end
-
-               -- Markdown
                content = self:md2html(content)
-
-       elseif string.match(file,'%.html?$') then
-               local i = '<[^>]+>'
-               -- Extract title from h1
-               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:gsub('(<h2[^>]*>)<[^>]+>','%1'),'<h2[^>]*>([^<>]+)',1) end
-
-       elseif not ngx.ctx.tmpl_content then
-               ishtml = false
-               if not vars.title then vars.title = string.match(content,'<title[^>]*>([^>]+)</title>',1) end
+       else
        end
 
        -- Header and footer
@@ -124,6 +105,22 @@ function nb:ngx_location_tmpl(fheader,ffooter)
                        .. inc_content
                        .. (content:sub(p2+1))
        end
+       content = self:html_fix(content)
+
+       --
+       -- Get title
+       --
+       content = template.compile(content,vars)(context)
+
+       -- Extract title from h1
+       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:gsub('(<h2[^>]*>)<[^>]+>','%1'),'<h2[^>]*>([^<>]+)',1)
+       end
 
        -- From request_uri
        if not vars.title then
@@ -145,8 +142,6 @@ function nb:ngx_location_tmpl(fheader,ffooter)
        -- Default first tld domain
        -- if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end
 
-       content = self:html_fix(content)
-
        -- See: /usr/local/share/lua/5.1/resty/template.lua
        -- Same as: template.print(template.compile(content,vars)(context))
        template.render(content,vars)