Skip to content

Commit

Permalink
Add rss
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph committed Oct 4, 2024
1 parent f70e5c2 commit e3775f0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@astrojs/check": "^0.9.1",
"@astrojs/cloudflare": "^11.0.4",
"@astrojs/rss": "^4.0.7",
"@astrojs/tailwind": "^5.1.0",
"astro": "^4.13.1",
"hono": "^4.5.4",
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/pages/all.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import Layout from "../layouts/default.astro";
let { objects: pages } = await Astro.locals.runtime.env.R2_BUCKET.list({
const { objects: pages } = await Astro.locals.runtime.env.R2_BUCKET.list({
prefix: "0",
// @ts-expect-error This is actually supported but the types are wrong
include: ["customMetadata"],
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/[...path].ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const app = new Hono<{ Bindings: AstroContext }>()
const customMetadata: Record<string, string> = {
slug,
};
["stage", "title", "published", "updated"].forEach((key) => {
["stage", "title", "published", "updated", "tags"].forEach((key) => {
if (props[key]) {
customMetadata[key] = props[key];
}
Expand Down
35 changes: 35 additions & 0 deletions src/pages/rss.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import rss, { type RSSFeedItem } from "@astrojs/rss";
import type { APIRoute } from "astro";

export const GET: APIRoute = async (context) => {
const { objects: pages } = await context.locals.runtime.env.R2_BUCKET.list({
prefix: "0",
// @ts-expect-error This is actually supported but the types are wrong
include: ["customMetadata"],
});

const items: RSSFeedItem[] = pages
.filter(
(page) =>
page.customMetadata?.stage !== "draft" &&
page.customMetadata?.title &&
page.customMetadata?.published &&
page.customMetadata?.slug
)
.map((page) => ({
title: page.customMetadata?.title,
pubDate:
!page.customMetadata?.tags?.includes("events") &&
page.customMetadata?.updated
? new Date(page.customMetadata?.updated)
: new Date(page.customMetadata?.published!),
link: `${context.locals.runtime.env.SITE}/${page.customMetadata?.slug}`,
}));

return rss({
title: "Just Be",
description: "The personal site of Justin Bennett",
site: context.locals.runtime.env.SITE,
items,
});
};

0 comments on commit e3775f0

Please sign in to comment.