diff options
-rwxr-xr-x | convert_md_to_asciidoc.sh | 4 | ||||
-rw-r--r-- | put_in_db.js | 21 | ||||
-rwxr-xr-x | put_in_db.sh | 10 | ||||
-rwxr-xr-x | server.js | 24 | ||||
-rw-r--r-- | views/index.ejs | 2 |
5 files changed, 50 insertions, 11 deletions
diff --git a/convert_md_to_asciidoc.sh b/convert_md_to_asciidoc.sh index bec8985..79b6442 100755 --- a/convert_md_to_asciidoc.sh +++ b/convert_md_to_asciidoc.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash for markdown in ./mds/*.md; do - name=$(basename -s ".md" ${markdown}) - pandoc -t asciidoc -f markdown ${markdown} > ./mds/${name}.txt + name=$(basename -s ".md" "${markdown}") + pandoc -t asciidoc -f markdown "${markdown}" > ./mds/"${name}".txt done diff --git a/put_in_db.js b/put_in_db.js index e5957df..e641187 100644 --- a/put_in_db.js +++ b/put_in_db.js @@ -1,9 +1,7 @@ "use strict"; -// mongosh --host 127.0.0.1 --port 27117 -u mongo -p mongo -f put_in_db.js const fs = require("fs"); const path = require("path"); -// db = connect("http://mongo:mongo@127.0.0.1:27117"); var blogs = [ { @@ -11,7 +9,7 @@ var blogs = [ slug: "c_struct_lua_table", body: fs.readFileSync(path.join(__dirname) + "/mds/cstruct2luatable.md"), teaser: fs.readFileSync(path.join(__dirname) + "/mds/cstruct2luatable.txt"), - keywords: "c,lua", + keywords: ["c", "lua"], lastUpdatedAt: Date.now(), }, { @@ -19,7 +17,7 @@ var blogs = [ slug: "lazy_makefile", body: fs.readFileSync(path.join(__dirname) + "/mds/lazymakefiles.md"), teaser: fs.readFileSync(path.join(__dirname) + "/mds/lazymakefiles.txt"), - keywords: "makefile,c,c++", + keywords: ["makefile", "c", "c++"], lastUpdatedAt: Date.now(), }, { @@ -31,7 +29,14 @@ var blogs = [ teaser: fs.readFileSync( path.join(__dirname) + "/mds/oneclientforeverything.txt", ), - keywords: "irc,matrix,mattermost,matterbridge,bitlbee,irssi", + keywords: [ + "irc", + "matrix", + "mattermost", + "matterbridge", + "bitlbee", + "irssi", + ], lastUpdatedAt: Date.now(), }, { @@ -43,7 +48,7 @@ var blogs = [ teaser: fs.readFileSync( path.join(__dirname) + "/mds/howtogetyourSMSonIRC.txt", ), - keywords: "irc,bot,sms", + keywords: ["irc", "bot", "sms"], lastUpdatedAt: Date.now(), }, { @@ -52,7 +57,7 @@ var blogs = [ slug: "what_to_do_with_your_dns", body: fs.readFileSync(path.join(__dirname) + "/mds/DNS.md"), teaser: fs.readFileSync(path.join(__dirname) + "/mds/DNS.txt"), - keywords: "DNS,DoH,DoT,ODoH,Tor,dnscrypt-proxy,vagrant", + keywords: ["DNS", "DoH", "DoT", "ODoH", "Tor", "dnscrypt-proxy", "vagrant"], lastUpdatedAt: Date.now(), }, { @@ -60,7 +65,7 @@ var blogs = [ slug: "after_ntp_comes_nts", body: fs.readFileSync(path.join(__dirname) + "/mds/NTP.md"), teaser: fs.readFileSync(path.join(__dirname) + "/mds/NTP.txt"), - keywords: "NTP,NTS,SOCKS5", + keywords: ["NTP", "NTS", "SOCKS5"], lastUpdatedAt: Date.now(), }, ]; diff --git a/put_in_db.sh b/put_in_db.sh new file mode 100755 index 0000000..0d76e13 --- /dev/null +++ b/put_in_db.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +MONGOSH=mongosh + +${MONGOSH} \ + --host 127.0.0.1 \ + --port 27117 \ + -u "$(cat ./mongo_secrets/mongo_user)" \ + -p "$(cat ./mongo_secrets/mongo_pass)" \ + -f put_in_db.js @@ -99,6 +99,23 @@ function renderAndSend_v2(req, res, slug) { }); } +function renderTagPage(req, res, tag) { + model.blogPost + .find( + { keywords: { $in: [tag] } }, + { projection: { _id: 0, title: 0, teaser: 0, body: 0, keywords: 0 } }, + ) + .exec(function (err, blogPosts) { + if (err) return err; + return res.render("tags.ejs", { + cache: true, + data: { + blogPosts: blogPosts, + }, + }); + }); +} + app.get("/health", (req, res) => { res.type("application/json"); let response = { isOK: "True", error: "" }; @@ -153,6 +170,13 @@ app.get("/posts/:postName", (req, res) => { renderAndSend_v2(req, res, req.params.postName); }); +app.get("/tags/:tagName", (req, res) => { + if (req.params["tagName"] == "") { + res.write("nothing requested!"); + } + renderTagPage(req, res, req.params.tagName); +}); + app.get("/$", (req, res) => { model.blogPost .find({}, { projection: { _id: 0, title: 0, teaser: 0 } }) diff --git a/views/index.ejs b/views/index.ejs index fdd49cc..606cdbb 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -15,7 +15,7 @@ <br/> <hr/> <br/> - <a class="left-footer">Keywords:</a> + <a class="left-footer">Keywords: </a> <%- data.keywords %> <%- data.lastUpdated %> <br/> |