From f9646ed19a79fc1530b6491c8acd19b04d84eac1 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 3 Jun 2018 23:29:44 +0100 Subject: [PATCH] lib/lua/nb.lua --- lib/lua/nb.lua | 22 +++++++++++----------- lib/postgres/{url.sql => content.sql} | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 14 deletions(-) rename lib/postgres/{url.sql => content.sql} (57%) diff --git a/lib/lua/nb.lua b/lib/lua/nb.lua index d8187e37..4253e743 100644 --- a/lib/lua/nb.lua +++ b/lib/lua/nb.lua @@ -86,7 +86,7 @@ function nb:ngx_location_tmpl(fheader,ffooter) end -- Header and footer - if ishtml and file ~= fheader and file ~= ffooter then + 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) content = header .. content .. footer @@ -118,6 +118,15 @@ function nb:ngx_location_tmpl(fheader,ffooter) .. (content:sub(p2+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 @@ -126,17 +135,8 @@ function nb:ngx_location_tmpl(fheader,ffooter) -- end -- 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 - -- Default first tld domain - if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end + -- if not vars.title then vars.title = string.match(ngx.var.http_host,'^([^%.]+)') end content = self:html_fix(content) template.render(content,vars) diff --git a/lib/postgres/url.sql b/lib/postgres/content.sql similarity index 57% rename from lib/postgres/url.sql rename to lib/postgres/content.sql index c9735241..3450d847 100644 --- a/lib/postgres/url.sql +++ b/lib/postgres/content.sql @@ -1,12 +1,17 @@ DROP TABLE IF EXISTS content; CREATE TABLE IF NOT EXISTS content ( - id SERIAL PRIMARY KEY, - type VARCHAR(250) NOT NULL, + -- id SERIAL PRIMARY KEY, + --id VARCHAR(500) PRIMARY KEY, + path VARCHAR(300), + file VARCHAR(100), title VARCHAR(250) NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - content TEXT NOT NULL + -- type VARCHAR(100) NOT NULL, + content TEXT NOT NULL, + PRIMARY KEY(path,file) ); + CREATE INDEX IF NOT EXISTS content_created ON content USING btree (created); CREATE INDEX IF NOT EXISTS content_type ON content USING btree (type); CREATE INDEX IF NOT EXISTS content_title ON content USING btree (title); @@ -26,3 +31,10 @@ CREATE TRIGGER content_before_insert BEFORE INSERT OR UPDATE ON content FOR EACH ROW EXECUTE PROCEDURE content_before_insert() ; + +COPY content (path, file, title, created, updated, content) FROM stdin; +/ test1.html Test 2018-06-03 11:59:16 2018-06-03 12:59:35.702535 This is a test +/ test2.html Test2 2018-06-03 11:59:39 2018-06-03 12:59:53.506176 Second text example +/a test1.html Test 2018-06-03 11:59:16 2018-06-03 12:59:35.702535 This is a test +/b test2.html Test2 2018-06-03 11:59:39 2018-06-03 12:59:53.506176 Second text example +\. -- 2.47.3