Skip to content

Commit

Permalink
implement feed generators
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Jun 28, 2024
1 parent 19cdf69 commit 74419f3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions codegen/codegen.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -17,4 +18,5 @@ function copyFiles() {
function generateFiles() {
generateTubes();
generateHTML();
generateFeed();
}
46 changes: 46 additions & 0 deletions codegen/feed.ts
Original file line number Diff line number Diff line change
@@ -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());
}
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 74419f3

Please sign in to comment.