Browse Source

Generate feeds for each tag

pull/230/head
Garrit Franke 1 year ago
parent
commit
5823f02978
Signed by: garrit
GPG Key ID: 65586C4DDA55EA2C
  1. 1
      .gitignore
  2. 21
      lib/rss.ts

1
.gitignore vendored

@ -34,5 +34,6 @@ yarn-error.log*
.vercel
public/rss.xml
public/feeds/
public/sitemap.xml
public/sitemap-0.xml

21
lib/rss.ts

@ -1,11 +1,13 @@
import { getPosts, Post } from "./posts";
import fs from "fs/promises";
import { existsSync } from "fs";
import path from "path";
import xmlFormat from "xml-formatter";
import rfc822Date from "rfc822-date";
import { markdown } from "markdown";
import { getAllTags } from "./tags";
const buildRss = async () => {
const posts = await getPosts();
@ -53,8 +55,25 @@ const buildRss = async () => {
};
const feedPath = path.join(__dirname, "../public/rss.xml");
await fs.writeFile(feedPath, xmlFormat(getRssXml(posts)), { flag: "w" });
const feedsDir = path.join(__dirname, "../public/feeds");
if (!existsSync(feedsDir)) {
await fs.mkdir(feedsDir);
}
const tags = (await getAllTags()).map(({ tag }) => tag);
tags.forEach(async (tag) => {
const feedPath = path.join(feedsDir, `${tag}.xml`);
const postsMatchingTags = posts.filter((post) => post.tags.includes(tag));
await fs.writeFile(feedPath, xmlFormat(getRssXml(postsMatchingTags)), {
flag: "w",
});
});
};
buildRss();

Loading…
Cancel
Save