From 69d905dad713253b63da55fb044e68f8a6ed5a55 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Thu, 13 Aug 2020 12:19:23 -0500 Subject: Remove client JS requirement from tag view --- src/html/tags.html | 39 --------------------------------------- src/server.js | 51 +++++++++++++++++++++++---------------------------- 2 files changed, 23 insertions(+), 67 deletions(-) delete mode 100644 src/html/tags.html (limited to 'src') diff --git a/src/html/tags.html b/src/html/tags.html deleted file mode 100644 index 9302993..0000000 --- a/src/html/tags.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - Mark's Kitchen - Blog - - - - - - - - - -
-

<{{tag}}

-
-
- - - \ No newline at end of file diff --git a/src/server.js b/src/server.js index 397cf9f..e62094b 100644 --- a/src/server.js +++ b/src/server.js @@ -67,7 +67,7 @@ function constructFeed(posts){ ${post.createdAt.toString().substring(0,10)}`) post.tags.forEach(tag => { html.push(` - ${tag} + ${tag} `) }) html.push(`

@@ -178,11 +178,32 @@ function setUpRoutes(models, jwtFunctions, database) { res.status(200).send(html.join("")) }) + server.get('/tags/:name', async (req, res) => { + const { name } = req.params; + const postsWithTag = await models.tags.findAll({ attributes: ["postId"], where: { text: name } }) + .map(function (x) { + return { id: x.postId } + }); + var posts = await models.posts.findAll({ + where: { [Op.or]: postsWithTag }, order: [['createdAt', 'DESC']] + }); + posts = posts.map(x => x.get({ plain: true })); + await addImagesAndTagsToPosts(models, posts) + + var html = [] + html.push(templates["blog"]["pre"]) + html.push(`

#${name}

`) + html.push(await constructFeed(posts)) + html.push(templates["footer"]) + html.push(templates["blog"]["post"]) + + res.status(200).send(html.join("")) + }) server.get('/admin', (req, res) => res.sendFile(__dirname + "/html/admin.html")); server.get('/login', (req, res) => res.sendFile(__dirname + "/html/login.html")) server.get('/email', (req, res) => res.sendFile(__dirname + "/html/email.html")) - server.get('/tags', (req, res) => res.sendFile(__dirname + "/html/tags.html")); + // server.get('/tags', (req, res) => res.sendFile(__dirname + "/html/tags.html")); server.get('/feed', (req, res) => res.sendFile(__dirname + "/html/feed.html")); server.get('/essay', (req, res) => res.sendFile(__dirname + "/html/essay.html")); server.get('/misc', (req, res) => res.sendFile(__dirname + "/html/misc.html")); @@ -203,19 +224,12 @@ function setUpRoutes(models, jwtFunctions, database) { turn: { [Op.ne]: {$col: 'userside'} } - - // database.where( - // database.col('userside'), - // database.col('turn') - // ) }}) - // var game = await database.query("select * from chessgames where userside != turn", { type: database.QueryTypes.SELECT }) res.status(200).send({game:game}); }) server.get('/chess/:name', async (req, res, next) => { const { name } = req.params; var game = await models.chessgames.findOne({where: {name: name}}) - //var game = await database.query("select * from chessgames where name = '"+name+"'", { type: database.QueryTypes.SELECT }) res.status(200).send({game:game}); }) server.get('/admin/emails', async (req, res, next) => { @@ -234,25 +248,6 @@ function setUpRoutes(models, jwtFunctions, database) { res.status(400).send(e.message); } }) - server.get('/tags/:name', async (req, res, next) => { - try { - const { name } = req.params; - const postsWithTag = await models.tags.findAll({ attributes: ["postId"], where: { text: name } }) - .map(function (x) { - return { id: x.postId } - }); - var posts = await models.posts.findAll({ - where: { [Op.or]: postsWithTag }, order: [['createdAt', 'DESC']] - }); - posts = posts.map(x => x.get({ plain: true })); - await addImagesAndTagsToPosts(models, posts) - res.status(200).send(posts); - next(); - } catch (e) { - console.error(e); - res.status(400).send(e.message); - } - }) server.get('/posts/:type', async (req, res, next) => { try { const { type } = req.params; -- cgit v1.2.3