diff options
author | Mark Powers <mark@marks.kitchen> | 2020-12-19 22:35:50 -0600 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2020-12-19 22:35:50 -0600 |
commit | 5a5b666794b688881eb1e1635bf9f2ceb3cc4346 (patch) | |
tree | 4b80da46e9ea1d6ada7df0792a46640de065d8a7 /src | |
parent | c18dd9ef6c9b3407862db7f01372bc65bb1c3721 (diff) |
Add title to posts
Diffstat (limited to 'src')
-rw-r--r-- | src/css/styles.css | 4 | ||||
-rw-r--r-- | src/html/admin.html | 3 | ||||
-rw-r--r-- | src/index.js | 3 | ||||
-rw-r--r-- | src/server.js | 40 | ||||
-rw-r--r-- | 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 @@ -42,6 +42,9 @@ <div class="form"> <form action="/admin/posts" method="post" enctype="multipart/form-data"> <div> + <input name="title" placeholder="title"> + </div> + <div> <textarea name="description"></textarea> </div> <div> 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(`<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) -} - 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 @@ <div class="feed"> {{#each posts}} <div class="card"> + {{#if this.showTitle}} + <h1 class="card-title">{{this.title}}</h1> + {{/if}} <p class="card-text">{{{this.description}}}</p> <div class="card-img"> {{#each this.images}} |