summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.js9
-rw-r--r--source/rss.js44
2 files changed, 52 insertions, 1 deletions
diff --git a/app.js b/app.js
index bb8e066..9b95eb1 100644
--- a/app.js
+++ b/app.js
@@ -32,6 +32,7 @@ const assetDir = [
'vid'
]
require('dotenv').config()
+const rss = require('./source/rss')({baseUrl: process.env.baseUrl})
// Handles the routes
class App {
@@ -77,12 +78,18 @@ class App {
this.data = this.readfile.GetRobots()
this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res}))
break
+ case 'rss':
+ rss.GetFeed({
+ title: process.env.rssTitle,
+ description: process.env.rssDescription,
+ author: process.env.rssAuthor
+ }).then(output => res.send(output))
+ break
default:
if (this.path.string.endsWith('/') && this.path.string.length > 1) this.path.string = this.path.string.substring(0, this.path.string.length - 1)
if (output.has(this.path.string)) {
try {
output.get(this.path.string).then(output => {
- console.log(output.meta)
res.send(this.readfile.GetMain(output.meta))
})
} catch {
diff --git a/source/rss.js b/source/rss.js
new file mode 100644
index 0000000..175a8c1
--- /dev/null
+++ b/source/rss.js
@@ -0,0 +1,44 @@
+const blog = require('./blog')()
+const rss = require('rss')
+
+class RSS {
+ constructor(x) {
+ this.object = {
+ feed: null,
+ baseUrl: x.baseUrl,
+ }
+ }
+
+ async GetFeed(x) {
+ if (this.object.feed) {
+ return this.object.feed
+ } else {
+ return await this.#CreateFeed(x).then(feed => {
+ this.object.feed = feed
+ return this.object.feed
+ })
+ }
+ }
+
+ async #CreateFeed(x) {
+ return blog.ReadBlogs().then(blogs => {
+ const feed = new rss({
+ title: x.title,
+ description: x.description,
+ author: x.author
+ })
+
+ blogs.forEach(value => {
+ feed.item({
+ title: value.title,
+ description: value.body,
+ url: `${this.object.baseUrl}blog`,
+ date: value.date
+ })
+ })
+ return feed.xml({ident: true})
+ })
+ }
+}
+
+module.exports = (x) => new RSS(x)