From 74419f3597ee14b00f05819a4f4153495f0c543a Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Fri, 28 Jun 2024 15:42:18 -0700 Subject: [PATCH] implement feed generators --- codegen/codegen.ts | 2 ++ codegen/feed.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ deno.json | 1 + 3 files changed, 49 insertions(+) create mode 100644 codegen/feed.ts diff --git a/codegen/codegen.ts b/codegen/codegen.ts index abd6494..5bcefc6 100644 --- a/codegen/codegen.ts +++ b/codegen/codegen.ts @@ -1,6 +1,7 @@ import { copySync } from "@std/fs"; import { generateTubes } from "./tubes.ts"; import { generateHTML } from "./html.tsx"; +import { generateFeed } from "./feed.ts"; if (import.meta.main) { copyFiles(); @@ -17,4 +18,5 @@ function copyFiles() { function generateFiles() { generateTubes(); generateHTML(); + generateFeed(); } diff --git a/codegen/feed.ts b/codegen/feed.ts new file mode 100644 index 0000000..a37da8e --- /dev/null +++ b/codegen/feed.ts @@ -0,0 +1,46 @@ +import { Feed } from "feed"; +import { posts } from "#/components/blog_page/data.ts"; + +const ORIGIN = "https://fart.tools"; +const ID = `${ORIGIN}/blog`; +const COPYRIGHT = `Copyright ${new Date().getFullYear()} FartLabs`; + +export function generateFeed() { + const feed = new Feed({ + id: ID, + link: ID, + copyright: COPYRIGHT, + language: "en", + title: "FartLabs Blog", + description: "Keep up with the latest from FartLabs!", + favicon: `${ORIGIN}/fl-logo.png`, + generator: "Feed (https://github.com/jpmonette/feed)", + feedLinks: { + rss: `${ID}/feed.xml`, + atom: `${ID}/feed.atom`, + }, + }); + posts.forEach((post) => { + feed.addItem({ + id: `${ORIGIN}/${post.id}`, + link: `${ORIGIN}/${post.id}`, + title: post.attrs.title, + description: post.attrs.description, + date: new Date(post.attrs.date), + published: new Date(post.attrs.date), + copyright: COPYRIGHT, + category: post.attrs.topics.map((topic) => ({ + name: topic.toLowerCase(), + })), + author: post.attrs.authors.map((author) => ({ + name: author.name, + link: author.username + ? `https://github.com/${author.username}` + : undefined, + })), + }); + }); + + Deno.writeTextFileSync("generated/blog/feed.xml", feed.rss2()); + Deno.writeTextFileSync("generated/blog/feed.atom", feed.atom1()); +} diff --git a/deno.json b/deno.json index e9d2fa9..e8e240d 100644 --- a/deno.json +++ b/deno.json @@ -12,6 +12,7 @@ "@std/fs": "jsr:@std/fs@^0.223.0", "@std/http": "jsr:@std/http@^0.223.0", "alea": "npm:alea@^1.0.1", + "feed": "npm:feed@^4.2.2", "highlight.js": "npm:highlight.js@^11.9.0", "markdown-it": "npm:markdown-it@^14.1.0", "markdown-it-anchor": "npm:markdown-it-anchor@^8.6.7",