aboutsummaryrefslogtreecommitdiff
path: root/src/server.js
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2021-02-23 20:09:29 -0600
committerMark Powers <mark@marks.kitchen>2021-02-23 20:09:29 -0600
commit8a0a3a00e75dc2351a7218d0059b87f7e9345871 (patch)
tree180a3dc0065db849301d0e87c11f129475c02eb5 /src/server.js
parent4ed0b48232f2d0fdaa1ed85f243119608d2d5caf (diff)
parent5b5dc610bc0da17fd006982de50b4dc74b134a54 (diff)
Merge branch 'master' of marks.kitchen:/srv/git/markskitchen
Diffstat (limited to 'src/server.js')
-rw-r--r--src/server.js65
1 files changed, 26 insertions, 39 deletions
diff --git a/src/server.js b/src/server.js
index 297c135..58d29fb 100644
--- a/src/server.js
+++ b/src/server.js
@@ -51,41 +51,9 @@ function hashWithSalt(password, salt){
return hash.digest("base64");
};
-function constructFeed(posts){
- var html = []
- html.push(`<div class="feed">`)
- posts.forEach(post => {
- html.push(`<div class="card">
- <p class="card-text">${post.description}</p>
- <div class="card-img">`)
- post.images.forEach(image => {
- html.push(`<span>
- <a href="/${image}"><img src="/${image}"></a>
- </span>`)
- })
- html.push(`</div>
- <p class="date">
- <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>
- </span>`)
- })
- html.push(`</p>
- </div>`)
- })
- html.push(`</div>`)
- return html.join("");
-}
-
-async function constructFeedFromType(models, postType){
- var posts = await models.posts.findAll({
- where: { type: postType }, order: [['createdAt', 'DESC']]
- });
- posts = posts.map(x => x.get({ plain: true }));
- await addImagesAndTagsToPosts(models, posts)
-
- return constructFeed(posts)
+function formatDate(d) {
+ let month = d.toLocaleString('default', { month: 'long' });
+ return month + " " + d.getDate() + ", " + (1900+d.getYear())
}
async function formatPostsforSingle(models, postType, postId){
@@ -98,7 +66,8 @@ async function formatPostsforSingle(models, postType, postId){
posts = posts.map(x => x.get({ plain: true }));
await addImagesAndTagsToPosts(models, posts)
posts.forEach(post => {
- post.createdAt = post.createdAt.toString().substring(0, 10)
+ post.createdAt = formatDate(post.createdAt)
+ post.showTitle = post.type != "bread"
})
return posts
}
@@ -110,7 +79,8 @@ async function formatPostsForType(models, postType){
posts = posts.map(x => x.get({ plain: true }));
await addImagesAndTagsToPosts(models, posts)
posts.forEach(post => {
- post.createdAt = post.createdAt.toString().substring(0, 10)
+ post.createdAt = formatDate(post.createdAt)
+ post.showTitle = post.type != "bread"
})
return posts;
}
@@ -177,7 +147,20 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
let body = templates["blog-single"]({posts, date});
res.status(200).send(body)
})
+<<<<<<< HEAD
server.get('/tags/:name', cache('5 minutes'), async (req, res) => {
+=======
+ server.get('/post/like/:type/:id', async (req, res) => {
+ let type = req.params.type
+ let id = req.params.id
+ var post = await models.posts.findOne({
+ where: { type, id },
+ });
+ post.update({likes: post.likes+1})
+ res.status(200).send({likes: post.likes});
+ })
+ server.get('/tags/:name', async (req, res) => {
+>>>>>>> 5b5dc610bc0da17fd006982de50b4dc74b134a54
const { name } = req.params;
const postsWithTag = await models.tags.findAll({ attributes: ["postId"], where: { text: name } })
.map(function (x) {
@@ -287,6 +270,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
try {
const type = req.body.type
req.body.description = marked(req.body.description)
+ req.body.likes = 0
const newPost = await models.posts.create(req.body);
req.files.forEach(async (file) => {
await models.pictures.create({ "source": "uploads/" + file.filename, "postId": newPost.id });
@@ -368,6 +352,9 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
server.get('/js/:id', cache('5 minutes'), (req, res) => {
res.sendFile(__dirname + "/js/" + req.params.id);
});
+ server.get('/res/:id', (req, res) => {
+ res.sendFile(__dirname + "/res/" + req.params.id);
+ });
server.get('/feed.xml', cache('1 hour'), async (req, res) => {
var feed = new rss({
@@ -375,7 +362,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
description: "Posts from marks.kitchen",
feed_url: "https://marks.kitchen/rss",
site_url: "https://marks.kitchen",
- webMaster: "webmaster@marks.kitchen",
+ webMaster: "webmaster@marks.kitchen (Mark Powers)",
copyright: "Mark Powers"
})
var posts = await models.posts.findAll({
@@ -384,7 +371,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
posts = posts.map(x => x.get({ plain: true }));
posts.forEach(post =>{
feed.item({
- title: post.createdAt.toString().substring(0, post.createdAt.toString().indexOf(" GMT")),
+ title: post.title,
description: post.description,
date: post.createdAt,
url: `https://marks.kitchen/post/${post.type}/${post.id}`,