![{article.title}]({`/a/${article.slug}.jpg`})
{article.title}
diff --git a/src/routes/a/_articles.js b/src/routes/a/_articles.js deleted file mode 100644 index 21ca03c..0000000 --- a/src/routes/a/_articles.js +++ /dev/null @@ -1,9 +0,0 @@ -const articles = [ -]; - -articles.forEach(article => { - article.slug = article.title.toLowerCase().replace(/\W+/g, '-'); - article.html = article.html.replace(/^\t{3}/gm, ''); -}); - -export default articles; diff --git a/src/routes/cms/create.svelte b/src/routes/cms/create.svelte index 4103d2e..3a21f2d 100644 --- a/src/routes/cms/create.svelte +++ b/src/routes/cms/create.svelte @@ -1,8 +1,8 @@ + +
+ < Back to Dashboard
+
diff --git a/src/routes/index.svelte b/src/routes/index.svelte
index ad9dc5f..0883500 100644
--- a/src/routes/index.svelte
+++ b/src/routes/index.svelte
@@ -1,7 +1,8 @@
@@ -94,14 +95,14 @@
Delete an Article
+-
+ {#each articles as article}
+
- + {article.title} by {article.author_user} + + + {:else} +
- There are no published articles. + {/each} +
Welcome
Find an Article
- {#each articles as {title, slug, date}}
+ {#each articles as {title, slug, image, created_at}}
-
+
{:else}
diff --git a/src/server.js b/src/server.js
index 51c08ec..75b3947 100644
--- a/src/server.js
+++ b/src/server.js
@@ -199,16 +199,43 @@ express()
}));
}
},
- function(req, res, next) {
- res.writeHead(200, {
- 'Content-Type': 'application/json'
- });
- res.end(JSON.stringify({
- message: `ur a faget lol`
- }));
+ async function(req, res, next) {
+ try {
+ const { html, title, image } = req.body;
+ if (!title || !image || !html) {
+ res.writeHead(422, {
+ 'Content-Type': 'application/json'
+ });
+ res.end(JSON.stringify({
+ message: `You must supply an article title, image URL, and content.`
+ }));
+ }
+ const article = await new Article({ html, title, image, author: req.user._id });
+ await article.save();
+ res.redirect(`/a/${article.slug}`);
+ } catch (err) {
+ res.writeHead(500, {
+ 'Content-Type': 'application/json'
+ });
+ res.end(JSON.stringify({
+ message: `Failed to add article: ${err}`
+ }));
+ }
}
)
+ .get('/a/all', async function (req, res, next) {
+ let articles = await Article.find().populate('author_user');
+ articles.forEach(article => {
+ article.slug = article.title.toLowerCase().replace(/\W+/g, '-');
+ article.html = article.html.replace(/^\t{3}/gm, '');
+ });
+ res.writeHead(200, {
+ 'Content-Type': 'application/json'
+ });
+ res.end(JSON.stringify(articles));
+ })
+
.use(compression({ threshold: 0 }))
.use(sirv('static', { dev }))
.use(sapper.middleware({
![{title}]({`/a/${slug}.jpg`)
{title}
-{new Date(date).toLocaleDateString()}
+{new Date(created_at).toLocaleDateString()}