From 54dd0968b1ea774a0cdaafd46a84965b08281b78 Mon Sep 17 00:00:00 2001 From: Flummi Date: Thu, 25 Aug 2016 21:44:40 +0200 Subject: [PATCH] testtpl --- s/test.css | 33 +++++++++++++++++++++++++++++++++ s/test.tpl.html | 16 ++++++++++++++++ src/websrv.js | 16 +++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 s/test.css create mode 100644 s/test.tpl.html diff --git a/s/test.css b/s/test.css new file mode 100644 index 0000000..ba56a9a --- /dev/null +++ b/s/test.css @@ -0,0 +1,33 @@ +body { + width: 100%; + margin: 1em auto 3em auto; + background-color: #262626; + color: #fff; + font-family: Monospace; +} +.body { + width: 90%; + margin: 1em auto 3em auto; + background-color: #262626; + color: #fff; + font-family: Monospace; +} +.thumb { + border: 0; + margin: 0 8px 8px 0; + float: left; + border: 2px solid #4c4a4a; +} +.thumb:hover { + opacity: 0.7; +} +.clear { + clear: both; + padding: 1em 0; +} +a { + color: #9f0; +} +a:hover { + color: #74c100; +} \ No newline at end of file diff --git a/s/test.tpl.html b/s/test.tpl.html new file mode 100644 index 0000000..fd9ffbc --- /dev/null +++ b/s/test.tpl.html @@ -0,0 +1,16 @@ + + + + f0ck me! + + + +
+ {% for item in items %} + + {% endfor %} +
+
+ + + \ No newline at end of file diff --git a/src/websrv.js b/src/websrv.js index b539bdd..10dba95 100644 --- a/src/websrv.js +++ b/src/websrv.js @@ -45,6 +45,19 @@ function Websrv(tbot, tsql, tcfg, tlib) { res.end(tpl(data), 'utf-8'); }); } + + else if(filePath == "./test") { // (test)mainpage + var tpl = swig.compile(templates.test); + var data = { items: [] }; + sql.query("select `id`,`mime` from `f0ck`.`items` order by `id` desc limit 20", (err, rows, fields) => { + rows.forEach((e,i,a) => { + data.items.push({ "id": e.id, "mime": e.mime }); + }); + res.writeHead(200, { 'Content-Type': 'text/html' }); + res.end(tpl(data), 'utf-8'); + }); + } + else if(Number.isInteger(parseInt(url))) { // itempage var query = "select * from `f0ck`.`items` where `id` = ? limit 1; " // get item + "select `id` from `f0ck`.`items` where `id` = (select min(`id`) from `f0ck`.`items` where `id` > ?); " // get previous item @@ -249,6 +262,7 @@ Websrv.prototype.getTpls = () => { "item": fs.readFileSync("./s/item.tpl.html", "utf-8"), "how": fs.readFileSync("./s/how.tpl.html", "utf-8"), "contact": fs.readFileSync("./s/contact.tpl.html", "utf-8"), - "scripts": fs.readFileSync("./s/scripts.tpl.html", "utf-8") + "scripts": fs.readFileSync("./s/scripts.tpl.html", "utf-8"), + "test": fs.readFileSync("./s/test.tpl.html", "utf-8") }; }; \ No newline at end of file