From: Nicolas Boisselier Date: Thu, 14 Jun 2018 01:09:35 +0000 (+0100) Subject: etc/profile.d/functions X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=0a0fd06519aa87d209acda88d9bc3dd3678750d1;p=nb.git etc/profile.d/functions --- diff --git a/etc/profile.d/functions b/etc/profile.d/functions index 0279a551..c4abb4d0 100755 --- a/etc/profile.d/functions +++ b/etc/profile.d/functions @@ -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 diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index b05229a6..62fea668 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -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('(]*>)<[^>]+>','%1'),']*>([^<>]+)',1) end - -- Extract title from h2 - if not vars.title then vars.title = string.match(content:gsub('(]*>)<[^>]+>','%1'),']*>([^<>]+)',1) end - - elseif not ngx.ctx.tmpl_content then - ishtml = false - if not vars.title then vars.title = string.match(content,']*>([^>]+)',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('(]*>)<[^>]+>','%1'),']*>([^<>]+)',1) + end + + -- Extract title from h2 + if not vars.title then + vars.title = string.match(content:gsub('(]*>)<[^>]+>','%1'),']*>([^<>]+)',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)