diff options
| author | Mhykol <mchaeldonald62@pm.me> | 2024-06-21 08:31:02 -0400 |
|---|---|---|
| committer | Mhykol <mchaeldonald62@pm.me> | 2024-06-21 08:31:02 -0400 |
| commit | 1dd31494f0e270f24c2caad411e271b9bf5c781c (patch) | |
| tree | b06e0dd38a4e6c2a2e365169834cc2ab7bd68fcd /source | |
| parent | d7e95b22addb636c2f1fff42ccc46253cb3a3732 (diff) | |
Added rss feed for blog
Diffstat (limited to 'source')
| -rw-r--r-- | source/rss.js | 44 |
1 files changed, 44 insertions, 0 deletions
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) |
