const { Feed } = require("feed"); const fs = require("fs"); const util = require("./util"); const converter = util.showdown(1); let folder = `${__dirname}/../`; console.log("Refreshing feeds..."); createFeed(function (feed) { fs.writeFile(`${folder}feed.json`, feed.json1(), function (_) {}); fs.writeFile(`${folder}rss.xml`, feed.rss2(), function (_) {}); fs.writeFile(`${folder}atom.xml`, feed.atom1(), function (_) {}); }); function createFeed(callback) { const feed = new Feed({ title: "Ellpeck's Blog", description: "Occasionally I enjoy writing stuff. So here's some of the stuff I've written about gaming, programming and life.", id: "https://ellpeck.de/", link: "https://ellpeck.de/", image: "https://ellpeck.de/res/logo.png", favicon: "https://ellpeck.de/favicon.ico", language: "en", feedLinks: { json: "https://ellpeck.de/feed.json", atom: "https://ellpeck.de/atom.xml", rss: "https://ellpeck.de/rss.xml" }, author: { name: "Ellpeck", email: "me@ellpeck.de", link: "https://ellpeck.de/" } }); const finalCallback = callback; fs.readFile(`${__dirname}/../blog/src/posts.json`, function (_, data) { let json = JSON.parse(data); for (let i = json.length - 1; i >= 0; i--) { const post = json[i]; const date = new Date(post.date); const index = i; let extension = post.book ? "html" : "md"; fs.readFile(`${__dirname}/../blog/src/${post.id}.${extension}`, function (_, file) { let content = post.book ? util.extractBookData(file, post, false) : converter.makeHtml(file.toString()); feed.addItem({ title: `${post.name}${post.archived ? " (Archived)" : ""}`, link: `https://ellpeck.de/blog/${post.id}`, description: post.summary, content: content, date: date, published: date, category: post.cat.map(c => ({ name: c })) }); if (index === 0) finalCallback(feed); }); } }); }