2019-10-04 23:20:47 +02:00
|
|
|
const {
|
|
|
|
Feed
|
|
|
|
} = require("feed");
|
|
|
|
const fs = require("fs");
|
2021-03-31 19:56:33 +02:00
|
|
|
const util = require("./util");
|
|
|
|
const converter = util.showdown(1);
|
2019-10-04 23:20:47 +02:00
|
|
|
|
2021-03-19 07:55:18 +01:00
|
|
|
let folder = `${__dirname}/../`;
|
2020-04-02 21:54:20 +02:00
|
|
|
console.log("Refreshing feeds...");
|
|
|
|
createFeed(function (feed) {
|
2021-03-19 07:55:18 +01:00
|
|
|
fs.writeFile(`${folder}feed.json`, feed.json1(), function (_) {});
|
|
|
|
fs.writeFile(`${folder}rss.xml`, feed.rss2(), function (_) {});
|
|
|
|
fs.writeFile(`${folder}atom.xml`, feed.atom1(), function (_) {});
|
2020-04-02 21:54:20 +02:00
|
|
|
});
|
2019-10-04 23:20:47 +02:00
|
|
|
|
|
|
|
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.",
|
2021-03-31 03:03:58 +02:00
|
|
|
id: "https://ellpeck.de/",
|
|
|
|
link: "https://ellpeck.de/",
|
2019-10-04 23:20:47 +02:00
|
|
|
image: "https://ellpeck.de/res/logo.png",
|
|
|
|
favicon: "https://ellpeck.de/favicon.ico",
|
2021-03-17 03:30:30 +01:00
|
|
|
language: "en",
|
2019-10-04 23:20:47 +02:00
|
|
|
feedLinks: {
|
|
|
|
json: "https://ellpeck.de/feed.json",
|
2021-03-17 03:30:30 +01:00
|
|
|
atom: "https://ellpeck.de/atom.xml",
|
|
|
|
rss: "https://ellpeck.de/rss.xml"
|
2019-10-04 23:20:47 +02:00
|
|
|
},
|
|
|
|
author: {
|
|
|
|
name: "Ellpeck",
|
|
|
|
email: "me@ellpeck.de",
|
2021-03-31 03:03:58 +02:00
|
|
|
link: "https://ellpeck.de/"
|
2019-10-04 23:20:47 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-19 12:02:31 +01:00
|
|
|
const finalCallback = callback;
|
2021-03-19 07:55:18 +01:00
|
|
|
fs.readFile(`${__dirname}/../blog/src/posts.json`, function (_, data) {
|
2019-10-04 23:33:45 +02:00
|
|
|
let json = JSON.parse(data);
|
2019-10-04 23:20:47 +02:00
|
|
|
for (let i = json.length - 1; i >= 0; i--) {
|
2021-03-19 12:02:31 +01:00
|
|
|
const post = json[i];
|
|
|
|
const date = new Date(post.date);
|
|
|
|
const index = i;
|
2021-03-31 19:36:32 +02:00
|
|
|
let extension = post.book ? "html" : "md";
|
|
|
|
fs.readFile(`${__dirname}/../blog/src/${post.id}.${extension}`, function (_, file) {
|
2021-04-06 19:29:04 +02:00
|
|
|
let content = post.book ? util.extractBookData(file, post, false) : converter.makeHtml(file.toString());
|
2019-10-04 23:20:47 +02:00
|
|
|
feed.addItem({
|
2021-03-19 07:55:18 +01:00
|
|
|
title: `${post.name}${post.archived ? " (Archived)" : ""}`,
|
|
|
|
link: `https://ellpeck.de/blog/${post.id}`,
|
2019-11-20 22:17:58 +01:00
|
|
|
description: post.summary,
|
2021-03-31 19:36:32 +02:00
|
|
|
content: content,
|
2019-10-04 23:20:47 +02:00
|
|
|
date: date,
|
2021-03-17 03:07:12 +01:00
|
|
|
published: date,
|
2021-03-31 02:48:13 +02:00
|
|
|
category: post.cat.map(c => ({
|
|
|
|
name: c
|
|
|
|
}))
|
2019-10-04 23:20:47 +02:00
|
|
|
});
|
|
|
|
|
2021-03-19 12:02:31 +01:00
|
|
|
if (index === 0)
|
|
|
|
finalCallback(feed);
|
2019-10-04 23:20:47 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|