diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2020-08-07 21:55:16 +0200 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2020-08-07 21:55:16 +0200 |
commit | 6116769757ddd88781129e7339fc7ff60a259337 (patch) | |
tree | 362f6512b72b38d1d7a796783b60fe5f24fadb4a /lib/generateRss.ts | |
parent | c941b9a7066f6fe5cfebf159feb7d00cd316f64d (diff) | |
download | kronikarz-6116769757ddd88781129e7339fc7ff60a259337.tar.gz kronikarz-6116769757ddd88781129e7339fc7ff60a259337.zip |
Add rss feed generation
Diffstat (limited to 'lib/generateRss.ts')
-rw-r--r-- | lib/generateRss.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/generateRss.ts b/lib/generateRss.ts new file mode 100644 index 0000000..2f341c0 --- /dev/null +++ b/lib/generateRss.ts @@ -0,0 +1,26 @@ +import * as fs from "fs" +import RSS from "rss"; + +import { FeedOptions } from "./interfaces"; +import Post from "./Post"; + +export function generateRss(posts: Array<Post>, feed_path: string, feedOptions: FeedOptions) { + const feed = new RSS(feedOptions); + const parsedPosts = posts.forEach((post) => { + const { title, content, path, date, author } = post.toApi(); + feed.item({ + title, + description: content, + url: feedOptions.site_url + path, + guid: path, + author, + date, + }) + }) + const xml = feed.xml(); + fs.writeFile(feed_path, xml, (err) => { + if (err) { + console.log(err); + } + }) +} |