Skip to content

Commit 0aa1a64

Browse files
authored
[Docs Site] Add product and area specific changelog feeds (#20990)
1 parent db45549 commit 0aa1a64

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import rss from "@astrojs/rss";
2+
import { getCollection } from "astro:content";
3+
import { getChangelogs, getRSSItems } from "~/util/changelog";
4+
import { slug } from "github-slugger";
5+
6+
import type {
7+
APIRoute,
8+
InferGetStaticPropsType,
9+
InferGetStaticParamsType,
10+
GetStaticPaths,
11+
} from "astro";
12+
13+
export const getStaticPaths = (async () => {
14+
const products = await getCollection("products", (e) =>
15+
Boolean(e.data.product.group),
16+
);
17+
18+
const areas = Object.entries(
19+
Object.groupBy(products, (p) => p.data.product.group),
20+
);
21+
22+
return areas.map(([area, products]) => {
23+
if (!products)
24+
throw new Error(`[Changelog] No products attributed to "${area}"`);
25+
26+
return {
27+
params: {
28+
area: slug(area),
29+
},
30+
props: {
31+
title: area,
32+
products,
33+
},
34+
};
35+
});
36+
}) satisfies GetStaticPaths;
37+
38+
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
39+
type Params = InferGetStaticParamsType<typeof getStaticPaths>;
40+
41+
export const GET: APIRoute<Props, Params> = async ({ props, locals }) => {
42+
const { title, products } = props;
43+
44+
const notes = await getChangelogs({
45+
filter: (e) => {
46+
return e.data.products.some((x) => products.some((y) => x.id === y.id));
47+
},
48+
});
49+
50+
const items = await getRSSItems({
51+
notes,
52+
locals,
53+
});
54+
55+
return rss({
56+
title: `Cloudflare changelogs | ${title}`,
57+
description: `Cloudflare changelogs for ${title} products`,
58+
site: "https://developers.cloudflare.com/changelog/",
59+
items,
60+
});
61+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import rss from "@astrojs/rss";
2+
import { getCollection } from "astro:content";
3+
import { getChangelogs, getRSSItems } from "~/util/changelog";
4+
5+
import type {
6+
APIRoute,
7+
InferGetStaticPropsType,
8+
InferGetStaticParamsType,
9+
GetStaticPaths,
10+
} from "astro";
11+
12+
export const getStaticPaths = (async () => {
13+
const products = await getCollection("products");
14+
15+
return products.map((product) => {
16+
return {
17+
params: {
18+
product: product.id,
19+
},
20+
props: {
21+
product,
22+
},
23+
};
24+
});
25+
}) satisfies GetStaticPaths;
26+
27+
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
28+
type Params = InferGetStaticParamsType<typeof getStaticPaths>;
29+
30+
export const GET: APIRoute<Props, Params> = async ({
31+
params,
32+
props,
33+
locals,
34+
}) => {
35+
const { data } = props.product;
36+
37+
const notes = await getChangelogs({
38+
filter: (e) => {
39+
return e.data.products.some(({ id }) => id === params.product);
40+
},
41+
});
42+
43+
const items = await getRSSItems({
44+
notes,
45+
locals,
46+
});
47+
48+
return rss({
49+
title: `Cloudflare changelogs | ${data.name}`,
50+
description: `Cloudflare changelogs for ${data.name}`,
51+
site: "https://developers.cloudflare.com/changelog/",
52+
items,
53+
});
54+
};

0 commit comments

Comments
 (0)