2019-10-04 23:20:47 +02:00
|
|
|
const {
|
|
|
|
Feed
|
|
|
|
} = require("feed");
|
|
|
|
const fs = require("fs");
|
2019-10-20 15:56:22 +02:00
|
|
|
const converter = require("./showdown")(1);
|
2019-10-04 23:20:47 +02:00
|
|
|
|
2019-10-05 01:07:38 +02:00
|
|
|
module.exports = function () {
|
|
|
|
let folder = __dirname + "/../";
|
2019-10-10 12:04:08 +02:00
|
|
|
createFeeds(folder);
|
|
|
|
|
2019-10-05 01:07:38 +02:00
|
|
|
fs.watchFile(folder + "blog/posts.json", function (curr, prev) {
|
|
|
|
if (curr.mtime == prev.mtime)
|
|
|
|
return;
|
2019-10-10 12:04:08 +02:00
|
|
|
createFeeds(folder);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function createFeeds(folder) {
|
|
|
|
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 (_, _) {});
|
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.",
|
|
|
|
id: "https://ellpeck.de",
|
|
|
|
link: "https://ellpeck.de",
|
|
|
|
image: "https://ellpeck.de/res/logo.png",
|
|
|
|
favicon: "https://ellpeck.de/favicon.ico",
|
|
|
|
feedLinks: {
|
|
|
|
json: "https://ellpeck.de/feed.json",
|
|
|
|
atom: "https://ellpeck.de/atom.xml"
|
|
|
|
},
|
|
|
|
author: {
|
|
|
|
name: "Ellpeck",
|
|
|
|
email: "me@ellpeck.de",
|
|
|
|
link: "https://ellpeck.de"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
fs.readFile(__dirname + "/../blog/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--) {
|
2019-10-04 23:33:45 +02:00
|
|
|
let post = json[i];
|
2019-11-20 22:17:58 +01:00
|
|
|
let date = new Date(post.date);
|
2019-10-04 23:20:47 +02:00
|
|
|
|
2019-11-20 22:17:58 +01:00
|
|
|
fs.readFile(__dirname + "/../blog/" + post.id + ".md", function (_, content) {
|
2019-10-04 23:33:45 +02:00
|
|
|
let html = converter.makeHtml(content.toString());
|
2019-10-04 23:20:47 +02:00
|
|
|
feed.addItem({
|
2019-11-20 22:17:58 +01:00
|
|
|
title: post.name,
|
|
|
|
link: "https://ellpeck.de/blog-" + post.id,
|
|
|
|
description: post.summary,
|
2019-10-04 23:20:47 +02:00
|
|
|
content: html,
|
|
|
|
date: date,
|
|
|
|
published: date
|
|
|
|
});
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
callback(feed);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|