Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/components/global/footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@
</a>

<a
href="https://ladybird.org/posts.rss"
href="/posts.rss"
class="w-8 h-8 flex items-center justify-center rounded-full bg-[#16141b] hover:bg-[#8a64e5]"
>
<img src="/assets/img/rss.svg" alt="RSS" />
</a>

<a
href="/newsletters.rss"
class="w-8 h-8 flex items-center justify-center rounded-full bg-[#16141b] hover:bg-[#8a64e5]"
>
<img src="/assets/img/rss.svg" alt="RSS" />
Expand Down
7 changes: 7 additions & 0 deletions src/components/global/head.astro
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ const defaultDescription =
title="Ladybird Browser Posts"
href={new URL("posts.rss", Astro.site)}
/>

<link
rel="alternate"
type="application/rss+xml"
title="Ladybird Browser Newsletters"
href={new URL("newsletters.rss", Astro.site)}
/>
21 changes: 21 additions & 0 deletions src/pages/newsletters.rss.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import type { APIContext } from "astro";

export async function GET(context: APIContext) {
const newsletters = await getCollection("newsletters");
return rss({
title: "Ladybird Browser Newsletters",
description: "Ladybird is a brand-new browser &amp; web engine",
site: context.site!,
items: newsletters
.filter((newsletter) => !newsletter.data.draft)
.map((newsletter) => ({
title: newsletter.data.title,
description: newsletter.data.description,
pubDate: newsletter.data.date,
link: `/newsletter/${newsletter.slug}`,
})),
trailingSlash: false,
});
}
45 changes: 44 additions & 1 deletion tests/rss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from "path";

const rootDir: string = path.join(__dirname, "../");

describe("RSS Feeds", () => {
describe("Posts RSS Feeds", () => {
const srcDir = path.join(rootDir, "/src/content/posts");
const distDir = path.join(rootDir, "/dist/");

Expand Down Expand Up @@ -49,3 +49,46 @@ describe("RSS Feeds", () => {
});
});
});

describe("Newsletters RSS Feeds", () => {
const srcDir = path.join(rootDir, "/src/content/newsletters");
const distDir = path.join(rootDir, "/dist/");

const mdFiles = fs
.readdirSync(srcDir)
.filter((file) => file.endsWith(".mdx"));
const nonDraftMdFiles = mdFiles.filter((file) => {
const filePath = path.join(srcDir, file);
const fileContent = fs.readFileSync(filePath);
return !fileContent.includes("draft: true");
});
const xmlFile = fs.readFileSync(path.join(distDir, "newsletters.rss"));

const parser = new XMLParser();
const parsedXML = parser.parse(xmlFile);

test("RSS Channel includes overall metadata", () => {
expect(parsedXML.rss.channel).toEqual(
expect.objectContaining({
title: "Ladybird Browser Newsletters",
description: "Ladybird is a brand-new browser &amp; web engine",
link: "https://ladybird.org",
})
);
});

test("XML should contain entries for every non-draft newsletter", () => {
expect(parsedXML.rss.channel.item).toBeArrayOfSize(nonDraftMdFiles.length);
parsedXML.rss.channel.item.forEach((item: any) => {
const itemAttributes = Object.keys(item);
expect(itemAttributes).toEqual(
expect.arrayContaining([
"title",
"link",
"description",
"pubDate",
])
);
});
});
});