From b4440c8cc991c1bf75330d95ebd6f8d3e187793d Mon Sep 17 00:00:00 2001
From: Raymonzut <40148684+Raymonzut@users.noreply.github.com>
Date: Mon, 29 Jun 2020 23:33:31 +0200
Subject: [PATCH] Swap /urls for /rss; complete RSS feed
---
server/routes/api/posts.js | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/server/routes/api/posts.js b/server/routes/api/posts.js
index 6785879..7509328 100644
--- a/server/routes/api/posts.js
+++ b/server/routes/api/posts.js
@@ -56,9 +56,9 @@ routes.set('/:id', async (req, res) => {
else res.send(results[0])
})
-// For the sitemap.xml, will be listed in the XML Sitemap Index
-routes.set('/urls', async (req, res) => {
- const re = /(\/api\/)?(.*)\/urls/g
+// Dynamic RSS feed
+routes.set('/rss.xml', async (req, res) => {
+ const re = /(\/api\/)?(.*)\/rss/g
const result = [...req.raw.originalUrl.matchAll(re)]
if (!result) {
notFoundResponse(res)
@@ -67,17 +67,24 @@ routes.set('/urls', async (req, res) => {
const endpoint = result [1] ? result[1][2] : result[0][2]
// Assumes https
- const BASE_URL = 'https://' + req.raw.hostname + endpoint
- const urls = posts.map(post =>
- `\n
- ${BASE_URL}?post=${post._id}
- ${post.date}
- never
- 0.9
- `
+ const BASE_URL = 'https://' + req.raw.hostname + endpoint
+ const ITEMS = posts.map(post =>
+ `\r\n -
+ ${post.title}
+ https://${req.raw.hostname}/posts?post=${post._id}
+ https://${req.raw.hostname}/posts?post=${post._id}
+ ${post.content}
+
`
).join("\n")
- const xml = `\r
- ${urls}\n\r`
+ const xml = `\n
+
+
+ Posts
+ https://${req.raw.hostname}
+ Personal blog
+ en-us
+ ${ITEMS}
+ \n`
res.header('Content-Type', 'application/xml')
res.status(200).send(xml)