Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rss #73

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

6 changes: 6 additions & 0 deletions src/layouts/base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const { title, description } = Astro.props;
{description && <meta name="description" content={description} />}
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<link
rel="alternate"
type="application/rss+xml"
title="Just Be"
href={new URL("rss.xml", Astro.site)}
/>
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
<ViewTransitions />
Expand Down
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 site = context.locals.runtime.env.SITE ?? "https://just-be.dev";

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?.updated
? new Date(page.customMetadata?.updated)
: new Date(page.customMetadata?.published!),
link: `${site}/${page.customMetadata?.slug}`,
}));

return rss({
title: "Just Be",
description: "The personal site of Justin Bennett",
site,
items,
});
};
Loading