aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package-lock.json9
-rw-r--r--package.json1
-rw-r--r--src/html/admin.html3
-rw-r--r--src/html/blog.html16
-rw-r--r--src/server.js28
-rw-r--r--src/templates.js20
6 files changed, 48 insertions, 29 deletions
diff --git a/package-lock.json b/package-lock.json
index 8b76a1d..1f39823 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -56,7 +56,7 @@
},
"array-flatten": {
"version": "1.1.1",
- "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+ "resolved": "http://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"asn1": {
@@ -669,9 +669,14 @@
"yallist": "^3.0.2"
}
},
+ "marked": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/marked/-/marked-1.1.1.tgz",
+ "integrity": "sha512-mJzT8D2yPxoPh7h0UXkB+dBj4FykPJ2OIfxAWeIHrvoHDkFxukV/29QxoFQoPM6RLEwhIFdJpmKBlqVM3s2ZIw=="
+ },
"media-typer": {
"version": "0.3.0",
- "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
+ "resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
},
"merge-descriptors": {
diff --git a/package.json b/package.json
index 13885fc..8012d6a 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
"cookie-parser": "^1.4.4",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
+ "marked": "^1.1.1",
"minimist": ">=0.2.1",
"multer": "^1.4.2",
"mysql2": "^1.7.0",
diff --git a/src/html/admin.html b/src/html/admin.html
index 363f5c0..6136b3c 100644
--- a/src/html/admin.html
+++ b/src/html/admin.html
@@ -8,6 +8,7 @@
<link rel="stylesheet" type="text/css" href="/css/styles.css">
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> -->
+ <!-- <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> -->
<script>
window.onload = function () {
var feed = new Vue({
@@ -39,7 +40,7 @@
<div>
<h1>Create Post</h1>
<div class="form">
- <form action="/posts" method="post" enctype="multipart/form-data">
+ <form action="/admin/posts" method="post" enctype="multipart/form-data">
<div>
<textarea name="description"></textarea>
</div>
diff --git a/src/html/blog.html b/src/html/blog.html
index c0662f7..03a37e4 100644
--- a/src/html/blog.html
+++ b/src/html/blog.html
@@ -33,22 +33,6 @@
<a class="navigation" href="/" title="marks.kitchen">&lt;</a>
Blog
</h1>
- <!-- <div id="feed" class="feed">
- <div class="card" v-for="post in posts">
- <p class="card-text" v-html="post.description"></p>
- <div class="card-img">
- <span v-for="image in post.images">
- <a v-bind:href="image"><img v-bind:src="image"></a>
- </span>
- </div>
- <p class="date">
- <a v-bind:href="'/blog/'+post.id">{{{ post.createdAt.substring(0,10) }}}</a>
- <span v-for="tag in post.tags">
- <a class="tag" v-bind:href="'/tags#'+tag">{{tag}}</a>
- </span>
- </p>
- </div>
- </div> -->
<div id="feed" class="feed"></div>
</div>
</body>
diff --git a/src/server.js b/src/server.js
index 8114172..522823d 100644
--- a/src/server.js
+++ b/src/server.js
@@ -6,6 +6,7 @@ const crypto = require('crypto');
const uuidv4 = require('uuid/v4');
const path = require('path');
const rss = require('rss');
+const marked = require('marked');
const templates = require('./templates');
@@ -132,24 +133,29 @@ function setUpRoutes(models, jwtFunctions, database) {
html.push(templates["index"]["post"])
res.status(200).send(html.join(""))
- // res.sendFile(__dirname + "/html/index.html")
})
server.get('/bread', async (req, res) => {
var html = []
html.push(templates["bread"]["pre"])
- // html.push(templates["titlebar"])
html.push(await constructFeed(models, "bread"))
html.push(templates["footer"])
html.push(templates["bread"]["post"])
res.status(200).send(html.join(""))
- // res.sendFile(__dirname + "/html/index.html")
})
+ server.get('/blog', async (req, res) => {
+ var html = []
+ html.push(templates["blog"]["pre"])
+ html.push(await constructFeed(models, "blog"))
+ 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('/bread', (req, res) => res.sendFile(__dirname + "/html/bread.html"));
- server.get('/blog', (req, res) => res.sendFile(__dirname + "/html/blog.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"));
@@ -255,18 +261,20 @@ function setUpRoutes(models, jwtFunctions, database) {
res.status(400).send(e.message);
}
})
- server.post('/posts', upload.array('images'), async (req, res, next) => {
+ server.post('/admin/posts', upload.array('images'), async (req, res, next) => {
try {
const type = req.body.type
+ req.body.description = marked(req.body.description)
const newPost = await models.posts.create(req.body);
req.files.forEach(async (file) => {
await models.pictures.create({ "source": "uploads/" + file.filename, "postId": newPost.id });
console.log("uploaded ", file.path);
})
- req.body.tags.split(" ").forEach(async (tag) => {
- await models.tags.create({ "text": tag, "postId": newPost.id });
- })
- console.log(newPost);
+ if(req.body.tags.trim().length > 0) {
+ req.body.tags.split(" ").forEach(async (tag) => {
+ await models.tags.create({ "text": tag, "postId": newPost.id });
+ })
+ }
res.redirect(`/${type}`);
next();
} catch (e) {
diff --git a/src/templates.js b/src/templates.js
index 07a774c..7f22bed 100644
--- a/src/templates.js
+++ b/src/templates.js
@@ -57,5 +57,25 @@ module.exports = {
Some highlights (and lowlights) of breadmaking`,
post: `</body>
</html>`
+ },
+ blog: {
+ pre: `<!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">
+ <link rel="shortcut icon" href="/favicon.ico">
+ </head>
+
+ <body>
+ <h1>
+ <a class="navigation" href="/" title="marks.kitchen">&lt;</a>
+ Blog
+ </h1>`,
+ post: `</body>
+ </html>`
}
} \ No newline at end of file