}
--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
local content = self:readall(file)
if ngx.ctx.tmpl_content then content = ngx.ctx.tmpl_content end
if not content then return end
- if ngx.var.request_uri:match('^/dev/') then
- --content = template.compile(content,vars)(context)
- --ngx.print(content)
- --return
- end
local ishtml = true
if ngx.ctx.tmpl_content then
else
end
+ --
+ -- Get title
+ --
+ --local context
+ --content = template.compile(content,vars)(context)
+ --local sav = content
+ content = template.compile(content)(vars)
+ --content = sav
+
+ -- 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
+ local basename = string.match(ngx.var.request_uri,'([^/]+)/?$')
+ if basename then
+ local noext = string.match(basename,'([^%.]*)')
+ vars.title = noext
+ end
+ end
+
+ -- From filename
+-- if not vars.title then
+-- vars.title = string.match(file,'([^/%.]+)%.') -- basename
+-- if vars.title == 'index' then
+-- vars.title = string.match(file,'/([^/]+)/[^/]+$')
+-- end
+-- end
+
+ -- First tld domain
+ -- if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end
+
-- Header and footer
+ if not fheader then fheader = root .. "/tmpl/header.tmpl.html" end
+ if not ffooter then ffooter = root .. "/tmpl/footer.tmpl.html" end
+ --local header
+ --local footer
if ishtml and file ~= fheader and file ~= ffooter and not string.match(file,'/tmpl/') then
local header = self:readall(fheader)
local footer = self:readall(ffooter)
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
- local basename = string.match(ngx.var.request_uri,'([^/]+)/?$')
- if basename then
- local noext = string.match(basename,'([^%.]*)')
- vars.title = noext
- end
- end
-
- -- From filename
--- if not vars.title then
--- vars.title = string.match(file,'([^/%.]+)%.') -- basename
--- if vars.title == 'index' then
--- vars.title = string.match(file,'/([^/]+)/[^/]+$')
--- end
--- end
-
- -- Default first tld domain
- -- if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end
-
-- See: /usr/local/share/lua/5.1/resty/template.lua
- -- Same as: template.print(template.compile(content,vars)(context))
- template.render(content,vars)
+ -- Same as: template.print(template.compile(content)(vars))
+ --template.render(content,vars)
+ template.print(template.compile(content)(vars))
+ --template.print(vars.title)
+ --template.print(content)
ngx.exit(0)
end