aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/html/tags.html39
-rw-r--r--src/server.js51
2 files changed, 23 insertions, 67 deletions
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 @@
-<!doctype html>
-<html lang="en">
-
-<head>
- <title>Mark's Kitchen - Blog</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <link rel="stylesheet" type="text/css" href="/css/styles.css">
- <script src="/js/feed.js"></script>
- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
- <script>
- window.onload = window.onhashchange = function () {
- loadFeed(function () {
- var feed = new Vue({
- el: '#view',
- data: {
- posts: [],
- tag: window.location.hash
- },
- created() {
- console.log(this.tag);
- var tag = window.location.hash.substring(1);
- fetch(new Request(`/tags/${tag}`)).then(response => response.json())
- .then(response => this.posts = response);
- }
- });
- })
- }
- </script>
-</head>
-
-<body>
- <div id="view">
- <h1><a class="navigation" href="/" title="marks.kitchen">&lt;</a>{{tag}}</h1>
- <div id="feed"></div>
- </div>
-</body>
-
-</html> \ 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){
<a href="/post/${post.type}/${post.id}">${post.createdAt.toString().substring(0,10)}</a>`)
post.tags.forEach(tag => {
html.push(`<span>
- <a class="tag" href="/tags#${tag}">${tag}</a>
+ <a class="tag" href="/tags/${tag}">${tag}</a>
</span>`)
})
html.push(`</p>
@@ -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(`<h1>#${name}</h1>`)
+ 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;