Web/node/rss.js
Ell 23eea1d559
All checks were successful
Web/pipeline/head This commit looks good
moved the blog to its own directory
2021-03-11 03:21:23 +01:00

57 lines
No EOL
1.9 KiB
JavaScript

const {
Feed
} = require("feed");
const fs = require("fs");
const converter = require("./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",
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 + "/../blogsrc/posts.json", function (_, data) {
let json = JSON.parse(data);
for (let i = json.length - 1; i >= 0; i--) {
let post = json[i];
let date = new Date(post.date);
fs.readFile(__dirname + "/../blogsrc/" + post.id + ".md", function (_, content) {
let html = converter.makeHtml(content.toString());
feed.addItem({
title: post.name + (post.archived ? " (Archived)" : ""),
link: "https://ellpeck.de/blog/" + post.id,
description: post.summary,
content: html,
date: date,
published: date
});
if (i == 0) {
callback(feed);
}
});
}
});
}