Skip to content
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
22 changes: 22 additions & 0 deletions src/pages/changelog/rss/index.md.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import rss from "@astrojs/rss";
import type { APIRoute } from "astro";
import { getChangelogs, getRSSItems } from "~/util/changelog";

export const GET: APIRoute = async ({ locals }) => {
const notes = await getChangelogs({
filter: (entry) => !entry.data.hidden,
});

const items = await getRSSItems({
notes,
locals,
markdown: true,
});

return rss({
title: "Cloudflare changelogs",
description: `Variant of the Cloudflare changelog with Markdown content rather than HTML`,
site: "https://developers.cloudflare.com/changelog/",
items,
});
};
13 changes: 11 additions & 2 deletions src/util/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import rehypeParse from "rehype-parse";
import rehypeStringify from "rehype-stringify";
import rehypeBaseUrl from "~/plugins/rehype/base-url";
import rehypeFilterElements from "~/plugins/rehype/filter-elements";
import remarkGfm from "remark-gfm";
import rehypeRemark from "rehype-remark";
import remarkStringify from "remark-stringify";

export type GetChangelogsOptions = {
filter?: (entry: CollectionEntry<"changelog">) => boolean;
Expand Down Expand Up @@ -68,14 +71,15 @@ type GetRSSItemsOptions = {
*/
locals: App.Locals;
/**
* Returns Markdown in the `<content:encoded>` field instead of HTML.
* Returns Markdown in the `<description>` field instead of HTML.
*/
markdown?: boolean;
};

export async function getRSSItems({
notes,
locals,
markdown,
}: GetRSSItemsOptions): Promise<Array<RSSFeedItem>> {
return await Promise.all(
notes.map(async (note) => {
Expand All @@ -90,9 +94,14 @@ export async function getRSSItems({
rehypeParse,
rehypeBaseUrl,
rehypeFilterElements,
rehypeStringify,
];

if (markdown) {
plugins.push(remarkGfm, rehypeRemark, remarkStringify);
} else {
plugins.push(rehypeStringify);
}

const file = await unified()
.data("settings", {
fragment: true,
Expand Down