Skip to content

Commit 4cdd4fd

Browse files
KianNHdaisyfaithauma
authored andcommitted
[Docs Site] Add index.md.xml changelog variant (#21446)
1 parent 3eab1e1 commit 4cdd4fd

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import rss from "@astrojs/rss";
2+
import type { APIRoute } from "astro";
3+
import { getChangelogs, getRSSItems } from "~/util/changelog";
4+
5+
export const GET: APIRoute = async ({ locals }) => {
6+
const notes = await getChangelogs({
7+
filter: (entry) => !entry.data.hidden,
8+
});
9+
10+
const items = await getRSSItems({
11+
notes,
12+
locals,
13+
markdown: true,
14+
});
15+
16+
return rss({
17+
title: "Cloudflare changelogs",
18+
description: `Variant of the Cloudflare changelog with Markdown content rather than HTML`,
19+
site: "https://developers.cloudflare.com/changelog/",
20+
items,
21+
});
22+
};

src/util/changelog.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import rehypeParse from "rehype-parse";
1313
import rehypeStringify from "rehype-stringify";
1414
import rehypeBaseUrl from "~/plugins/rehype/base-url";
1515
import rehypeFilterElements from "~/plugins/rehype/filter-elements";
16+
import remarkGfm from "remark-gfm";
17+
import rehypeRemark from "rehype-remark";
18+
import remarkStringify from "remark-stringify";
1619

1720
export type GetChangelogsOptions = {
1821
filter?: (entry: CollectionEntry<"changelog">) => boolean;
@@ -68,14 +71,15 @@ type GetRSSItemsOptions = {
6871
*/
6972
locals: App.Locals;
7073
/**
71-
* Returns Markdown in the `<content:encoded>` field instead of HTML.
74+
* Returns Markdown in the `<description>` field instead of HTML.
7275
*/
7376
markdown?: boolean;
7477
};
7578

7679
export async function getRSSItems({
7780
notes,
7881
locals,
82+
markdown,
7983
}: GetRSSItemsOptions): Promise<Array<RSSFeedItem>> {
8084
return await Promise.all(
8185
notes.map(async (note) => {
@@ -90,9 +94,14 @@ export async function getRSSItems({
9094
rehypeParse,
9195
rehypeBaseUrl,
9296
rehypeFilterElements,
93-
rehypeStringify,
9497
];
9598

99+
if (markdown) {
100+
plugins.push(remarkGfm, rehypeRemark, remarkStringify);
101+
} else {
102+
plugins.push(rehypeStringify);
103+
}
104+
96105
const file = await unified()
97106
.data("settings", {
98107
fragment: true,

0 commit comments

Comments
 (0)