]> git.nbdom.net Git - nb.git/commitdiff
lib/lua/nb.lua
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 3 Jun 2018 22:29:44 +0000 (23:29 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 3 Jun 2018 22:29:44 +0000 (23:29 +0100)
lib/lua/nb.lua
lib/postgres/content.sql [new file with mode: 0644]
lib/postgres/url.sql [deleted file]

index d8187e37bdda556b500e64f1d16205ecfcf0560d..4253e7432b98968524fc1f87cbc4eec08134c40f 100644 (file)
@@ -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 (file)
index 0000000..3450d84
--- /dev/null
@@ -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 (file)
index c973524..0000000
+++ /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()
-;