From 5a5b666794b688881eb1e1635bf9f2ceb3cc4346 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sat, 19 Dec 2020 22:35:50 -0600 Subject: Add title to posts --- src/css/styles.css | 4 ++++ src/html/admin.html | 3 +++ src/index.js | 3 +++ src/server.js | 40 ++-------------------------------------- src/templates/feed.html | 3 +++ 5 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/css/styles.css b/src/css/styles.css index f406104..ab634ec 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -30,6 +30,10 @@ h1 { margin-left: 20px; } +.card-title { + margin-left: 0; +} + @keyframes zoom-left { 0% {left: 100%; } 100% {left: 0;} diff --git a/src/html/admin.html b/src/html/admin.html index 3eaa60a..29e4b87 100644 --- a/src/html/admin.html +++ b/src/html/admin.html @@ -41,6 +41,9 @@

Create Post

+
+ +
diff --git a/src/index.js b/src/index.js index 4b9a3c6..a94f8d0 100644 --- a/src/index.js +++ b/src/index.js @@ -53,6 +53,9 @@ function setUpModels(){ type: { type: Sequelize.STRING, allowNull: false, + }, + title: { + type: Sequelize.STRING, },}), "pictures": database.define('pictures', { source: { type: Sequelize.TEXT, allowNull: false}, diff --git a/src/server.js b/src/server.js index 2198923..81b7b0e 100644 --- a/src/server.js +++ b/src/server.js @@ -50,43 +50,6 @@ function hashWithSalt(password, salt){ return hash.digest("base64"); }; -function constructFeed(posts){ - var html = [] - html.push(`
`) - posts.forEach(post => { - html.push(`
-

${post.description}

-
`) - post.images.forEach(image => { - html.push(` - - `) - }) - html.push(`
-

- ${post.createdAt.toString().substring(0,10)}`) - post.tags.forEach(tag => { - html.push(` - ${tag} - `) - }) - html.push(`

-
`) - }) - html.push(`
`) - 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) -} - async function formatPostsforSingle(models, postType, postId){ var posts = await models.posts.findAll({ where: { @@ -110,6 +73,7 @@ async function formatPostsForType(models, postType){ await addImagesAndTagsToPosts(models, posts) posts.forEach(post => { post.createdAt = post.createdAt.toString().substring(0, 10) + post.showTitle = post.type != "bread" }) return posts; } @@ -384,7 +348,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}`, diff --git a/src/templates/feed.html b/src/templates/feed.html index 2158f3e..d7494a2 100644 --- a/src/templates/feed.html +++ b/src/templates/feed.html @@ -1,6 +1,9 @@
{{#each posts}}
+ {{#if this.showTitle}} +

{{this.title}}

+ {{/if}}

{{{this.description}}}

{{#each this.images}} -- cgit v1.2.3 From ed61b06cd842470c8155171889cdc51a0f9c7c93 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 20 Dec 2020 11:29:15 -0600 Subject: Update navigation --- src/templates/misc.html | 5 +---- src/templates/navigation.html | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/templates/misc.html b/src/templates/misc.html index ee641d1..3f0aee8 100644 --- a/src/templates/misc.html +++ b/src/templates/misc.html @@ -8,15 +8,12 @@ - +

< Miscellany

{{> navigation}} -
- Projects -
diff --git a/src/templates/navigation.html b/src/templates/navigation.html index 6bb10f1..ab53b13 100644 --- a/src/templates/navigation.html +++ b/src/templates/navigation.html @@ -5,6 +5,8 @@ Blog Games Email + Projects + Wiki Misc
- \ No newline at end of file + -- cgit v1.2.3 From 188a48b728080d8ffce1d304580964ea50b30a61 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 20 Dec 2020 11:36:29 -0600 Subject: Update README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b325d16..83bb85a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# marks.kitchen +My personal website engine. Allows for posting content from a web interface. +Uses handlesbars templates and a database backend via sequelize. + Configuration: - Requires mysql database. Include a `config.json` in `src` directory with the following structure: ```json -- cgit v1.2.3 From ee5600aac9548075634f51113f9b5ed078f82e12 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 20 Dec 2020 13:33:17 -0600 Subject: Fix date format on posts to show year --- src/server.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/server.js b/src/server.js index 81b7b0e..81f1edb 100644 --- a/src/server.js +++ b/src/server.js @@ -50,6 +50,11 @@ function hashWithSalt(password, salt){ return hash.digest("base64"); }; +function formatDate(d) { + let month = d.toLocaleString('default', { month: 'long' }); + return month + " " + d.getDate() + ", " + (1900+d.getYear()) +} + async function formatPostsforSingle(models, postType, postId){ var posts = await models.posts.findAll({ where: { @@ -60,7 +65,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 } @@ -72,7 +78,7 @@ 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; -- cgit v1.2.3 From 572671a916335fbbe8766b37b683b8a585c49abd Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Thu, 24 Dec 2020 12:48:58 -0600 Subject: Add background changer and css --- src/css/styles.css | 12 +++++++++++- src/icon/favicon.ico | Bin 1150 -> 0 bytes src/icon/favicon.svg | 1 - src/js/background.js | 29 +++++++++++++++++++++++++++++ src/res/change.jpg | Bin 0 -> 4689611 bytes src/res/day.jpg | Bin 0 -> 3710493 bytes src/res/favicon.ico | Bin 0 -> 1150 bytes src/res/favicon.svg | 1 + src/res/night.jpg | Bin 0 -> 4125007 bytes src/server.js | 9 ++++++--- src/templates/footer.html | 6 +++++- src/templates/navigation.html | 18 ++++++++---------- 12 files changed, 60 insertions(+), 16 deletions(-) delete mode 100644 src/icon/favicon.ico delete mode 100644 src/icon/favicon.svg create mode 100644 src/js/background.js create mode 100644 src/res/change.jpg create mode 100644 src/res/day.jpg create mode 100644 src/res/favicon.ico create mode 100644 src/res/favicon.svg create mode 100644 src/res/night.jpg diff --git a/src/css/styles.css b/src/css/styles.css index ab634ec..3a555cb 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -11,11 +11,16 @@ body { - width: 80%; + width: 60%; + min-width: 500px; margin: auto; /* margin: 0px; */ background-color: var(--background); font-family: Arial, Helvetica, sans-serif; + height: 100%; + background-position: center; + background-repeat: no-repeat; + background-size: cover; } h1, h2 { @@ -119,12 +124,17 @@ p { border-top: 1px solid var(--light-text); border-bottom: 1px solid var(--light-text); background-color: var(--background-accent); + display: flex; + flex-wrap: wrap; + justify-content: space-evenly; } + .titlebar a{ margin: auto; max-width: 10%; min-width: 100px; + flex-grow: 1; } .btn { diff --git a/src/icon/favicon.ico b/src/icon/favicon.ico deleted file mode 100644 index 7646b67..0000000 Binary files a/src/icon/favicon.ico and /dev/null differ diff --git a/src/icon/favicon.svg b/src/icon/favicon.svg deleted file mode 100644 index ad339b8..0000000 --- a/src/icon/favicon.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/js/background.js b/src/js/background.js new file mode 100644 index 0000000..f8a7684 --- /dev/null +++ b/src/js/background.js @@ -0,0 +1,29 @@ +function set_background_image(){ + let date = new Date(); + let current_hour = date.getHours() + if(current_hour <= 8 || current_hour >= 20){ + var photo = "night.jpg" + } else if(current_hour <= 10 || current_hour > 17){ + var photo = "change.jpg" + } else { + var photo = "day.jpg" + } + let btn = document.getElementById("loadBtn") + if(btn){ + btn.remove() + } + if(!document.getElementById("backgroundId")){ + document.body.style.backgroundImage = `url('/res/${photo}')`; + let desc = document.createElement("p") + desc.id = "backgroundId" + desc.innerHTML = "Background images in the public domain, painted by Ivan Konstantinovich Aivazovsky." + footer.appendChild(desc) + } +} +let el = document.createElement("a") +el.id = "loadBtn" +el.innerText = "load background" +el.onclick = set_background_image +let footer = document.getElementsByTagName("footer")[0] +footer.appendChild(el) + diff --git a/src/res/change.jpg b/src/res/change.jpg new file mode 100644 index 0000000..0d0b1c3 Binary files /dev/null and b/src/res/change.jpg differ diff --git a/src/res/day.jpg b/src/res/day.jpg new file mode 100644 index 0000000..13c115c Binary files /dev/null and b/src/res/day.jpg differ diff --git a/src/res/favicon.ico b/src/res/favicon.ico new file mode 100644 index 0000000..7646b67 Binary files /dev/null and b/src/res/favicon.ico differ diff --git a/src/res/favicon.svg b/src/res/favicon.svg new file mode 100644 index 0000000..ad339b8 --- /dev/null +++ b/src/res/favicon.svg @@ -0,0 +1 @@ + diff --git a/src/res/night.jpg b/src/res/night.jpg new file mode 100644 index 0000000..9b9471c Binary files /dev/null and b/src/res/night.jpg differ diff --git a/src/server.js b/src/server.js index 81f1edb..d820cd7 100644 --- a/src/server.js +++ b/src/server.js @@ -324,8 +324,8 @@ function setUpRoutes(models, jwtFunctions, database, templates) { }) - server.get('/favicon.ico', (req, res) => res.sendFile(__dirname + "/icon/favicon.ico")) - server.get('/favicon.svg', (req, res) => res.sendFile(__dirname + "/icon/favicon.svg")) + server.get('/favicon.ico', (req, res) => res.sendFile(__dirname + "/res/favicon.ico")) + server.get('/favicon.svg', (req, res) => res.sendFile(__dirname + "/res/favicon.svg")) server.get('/css/:id', (req, res) => { res.sendFile(__dirname + "/css/" + req.params.id); }); @@ -338,6 +338,9 @@ function setUpRoutes(models, jwtFunctions, database, templates) { server.get('/js/:id', (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', async (req, res) => { var feed = new rss({ @@ -345,7 +348,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({ diff --git a/src/templates/footer.html b/src/templates/footer.html index 617b5fa..6dc5a48 100644 --- a/src/templates/footer.html +++ b/src/templates/footer.html @@ -11,4 +11,8 @@
- \ No newline at end of file +
+ + +
+ diff --git a/src/templates/navigation.html b/src/templates/navigation.html index ab53b13..b101bab 100644 --- a/src/templates/navigation.html +++ b/src/templates/navigation.html @@ -1,12 +1,10 @@ -- cgit v1.2.3 From 5137bb9b277fcd45327680166c9e39f26ec48c45 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Wed, 30 Dec 2020 22:28:39 -0600 Subject: Add like button to posts --- src/css/styles.css | 17 +++++++++++++++-- src/index.js | 6 +++++- src/server.js | 10 ++++++++++ src/templates/feed.html | 5 ++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/css/styles.css b/src/css/styles.css index 3a555cb..88d8e68 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -8,7 +8,6 @@ --btn-hover: #0a0; --light-text: #aaa; } - body { width: 60%; @@ -142,7 +141,6 @@ p { padding: 1px 3px; border: 1px solid var(--btn-text); border-radius: 3px; - width: 100%; max-width: 100px; line-height: 2em; text-align: center; @@ -152,6 +150,7 @@ p { } .btn-primary { + width: 100%; height: 2em; font-size: 20px; background-color: var(--btn-color); @@ -162,6 +161,15 @@ p { background-color: var(--btn-hover); } +.btn-secondary { + background-color: var(--btn-color); + color: var(--btn-text); +} + +.btn-secondary:hover{ + background-color: var(--btn-hover); +} + .date { font-style: italic; margin: 0em; @@ -223,3 +231,8 @@ a.navigation:visited, a.navigation:link { .email::after { content: "@marks.kitchen"; } + +a.cool { + float: right; +} + diff --git a/src/index.js b/src/index.js index a94f8d0..7ceecf0 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,11 @@ function setUpModels(){ }, title: { type: Sequelize.STRING, - },}), + }, + likes: { + type: Sequelize.INTEGER, + } + }), "pictures": database.define('pictures', { source: { type: Sequelize.TEXT, allowNull: false}, }), diff --git a/src/server.js b/src/server.js index d820cd7..cd76b5d 100644 --- a/src/server.js +++ b/src/server.js @@ -146,6 +146,15 @@ function setUpRoutes(models, jwtFunctions, database, templates) { let body = templates["blog-single"]({posts, date}); res.status(200).send(body) }) + 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.redirect(`/post/${type}/${id}`); + }) server.get('/tags/:name', async (req, res) => { const { name } = req.params; const postsWithTag = await models.tags.findAll({ attributes: ["postId"], where: { text: name } }) @@ -258,6 +267,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) { const type = req.body.type req.body.description = marked(req.body.description) const newPost = await models.posts.create(req.body); + newPost.likes = 0 req.files.forEach(async (file) => { await models.pictures.create({ "source": "uploads/" + file.filename, "postId": newPost.id }); console.log("uploaded ", file.path); diff --git a/src/templates/feed.html b/src/templates/feed.html index d7494a2..ae3494c 100644 --- a/src/templates/feed.html +++ b/src/templates/feed.html @@ -21,7 +21,10 @@ {{this}} {{/each}} + + 👍 ({{this.likes}}) +

{{/each}} -
\ No newline at end of file + -- cgit v1.2.3 From f2d7673d9743676fcd01d7ab26e7e60d9e21bc8f Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Wed, 30 Dec 2020 22:51:22 -0600 Subject: Fix likes starting at 0 --- src/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.js b/src/server.js index cd76b5d..07da08c 100644 --- a/src/server.js +++ b/src/server.js @@ -266,8 +266,8 @@ 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); - newPost.likes = 0 req.files.forEach(async (file) => { await models.pictures.create({ "source": "uploads/" + file.filename, "postId": newPost.id }); console.log("uploaded ", file.path); -- cgit v1.2.3 From 5b5dc610bc0da17fd006982de50b4dc74b134a54 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Tue, 5 Jan 2021 20:25:10 -0600 Subject: Refactor likes to use JS to avoid redirect --- src/css/styles.css | 3 ++- src/js/like.js | 11 +++++++++++ src/server.js | 2 +- src/templates/feed.html | 4 ++-- src/templates/header.html | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 src/js/like.js diff --git a/src/css/styles.css b/src/css/styles.css index 88d8e68..4572569 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -147,6 +147,7 @@ p { vertical-align: middle; white-space: nowrap; text-decoration: none; + cursor: pointer; } .btn-primary { @@ -232,7 +233,7 @@ a.navigation:visited, a.navigation:link { content: "@marks.kitchen"; } -a.cool { +.cool { float: right; } diff --git a/src/js/like.js b/src/js/like.js new file mode 100644 index 0000000..cd1e015 --- /dev/null +++ b/src/js/like.js @@ -0,0 +1,11 @@ +function likePost(type, id){ + fetch(`/post/like/${type}/${id}`) + .then(response => response.json()) + .then(response => { + console.log(response) + let btn_id=`btn_${type}_${id}` + let el = document.getElementById(btn_id) + el.innerText = `👍 (${response.likes})` + }) +} + diff --git a/src/server.js b/src/server.js index 07da08c..773feb0 100644 --- a/src/server.js +++ b/src/server.js @@ -153,7 +153,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) { where: { type, id }, }); post.update({likes: post.likes+1}) - res.redirect(`/post/${type}/${id}`); + res.status(200).send({likes: post.likes}); }) server.get('/tags/:name', async (req, res) => { const { name } = req.params; diff --git a/src/templates/feed.html b/src/templates/feed.html index ae3494c..3ea4f16 100644 --- a/src/templates/feed.html +++ b/src/templates/feed.html @@ -21,9 +21,9 @@ {{this}} {{/each}} - + 👍 ({{this.likes}}) - +

{{/each}} diff --git a/src/templates/header.html b/src/templates/header.html index 2ceebfd..1989b04 100644 --- a/src/templates/header.html +++ b/src/templates/header.html @@ -2,4 +2,4 @@ - + -- cgit v1.2.3