From: Nicolas Boisselier Date: Sun, 3 Jun 2018 22:29:44 +0000 (+0100) Subject: lib/lua/nb.lua X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=f9646ed19a79fc1530b6491c8acd19b04d84eac1;p=nb.git lib/lua/nb.lua --- 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/content.sql b/lib/postgres/content.sql new file mode 100644 index 00000000..3450d847 --- /dev/null +++ b/lib/postgres/content.sql @@ -0,0 +1,40 @@ +DROP TABLE IF EXISTS content; +CREATE TABLE IF NOT EXISTS content ( + -- 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, + -- 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); + +DROP FUNCTION IF EXISTS content_before_insert(); +/* +*/ +CREATE FUNCTION content_before_insert() RETURNS trigger as 'BEGIN + NEW.updated = now(); + RETURN NEW; +END' LANGUAGE 'plpgsql'; + +DROP TRIGGER IF EXISTS content_before_insert ON content; +/* +*/ +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 +\. diff --git a/lib/postgres/url.sql b/lib/postgres/url.sql deleted file mode 100644 index c9735241..00000000 --- a/lib/postgres/url.sql +++ /dev/null @@ -1,28 +0,0 @@ -DROP TABLE IF EXISTS content; -CREATE TABLE IF NOT EXISTS content ( - id SERIAL PRIMARY KEY, - type VARCHAR(250) NOT NULL, - title VARCHAR(250) NOT NULL, - created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - content TEXT NOT NULL -); -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); - -DROP FUNCTION IF EXISTS content_before_insert(); -/* -*/ -CREATE FUNCTION content_before_insert() RETURNS trigger as 'BEGIN - NEW.updated = now(); - RETURN NEW; -END' LANGUAGE 'plpgsql'; - -DROP TRIGGER IF EXISTS content_before_insert ON content; -/* -*/ -CREATE TRIGGER content_before_insert BEFORE INSERT OR UPDATE ON content -FOR EACH ROW -EXECUTE PROCEDURE content_before_insert() -;