diff --git a/src/pages/changelog/rss/[area].xml.ts b/src/pages/changelog/rss/[area].xml.ts new file mode 100644 index 00000000000000..cbbeb5791103e3 --- /dev/null +++ b/src/pages/changelog/rss/[area].xml.ts @@ -0,0 +1,61 @@ +import rss from "@astrojs/rss"; +import { getCollection } from "astro:content"; +import { getChangelogs, getRSSItems } from "~/util/changelog"; +import { slug } from "github-slugger"; + +import type { + APIRoute, + InferGetStaticPropsType, + InferGetStaticParamsType, + GetStaticPaths, +} from "astro"; + +export const getStaticPaths = (async () => { + const products = await getCollection("products", (e) => + Boolean(e.data.product.group), + ); + + const areas = Object.entries( + Object.groupBy(products, (p) => p.data.product.group), + ); + + return areas.map(([area, products]) => { + if (!products) + throw new Error(`[Changelog] No products attributed to "${area}"`); + + return { + params: { + area: slug(area), + }, + props: { + title: area, + products, + }, + }; + }); +}) satisfies GetStaticPaths; + +type Props = InferGetStaticPropsType; +type Params = InferGetStaticParamsType; + +export const GET: APIRoute = async ({ props, locals }) => { + const { title, products } = props; + + const notes = await getChangelogs({ + filter: (e) => { + return e.data.products.some((x) => products.some((y) => x.id === y.id)); + }, + }); + + const items = await getRSSItems({ + notes, + locals, + }); + + return rss({ + title: `Cloudflare changelogs | ${title}`, + description: `Cloudflare changelogs for ${title} products`, + site: "https://developers.cloudflare.com/changelog/", + items, + }); +}; diff --git a/src/pages/changelog/rss/[product].xml.ts b/src/pages/changelog/rss/[product].xml.ts new file mode 100644 index 00000000000000..1118aeb7c29358 --- /dev/null +++ b/src/pages/changelog/rss/[product].xml.ts @@ -0,0 +1,54 @@ +import rss from "@astrojs/rss"; +import { getCollection } from "astro:content"; +import { getChangelogs, getRSSItems } from "~/util/changelog"; + +import type { + APIRoute, + InferGetStaticPropsType, + InferGetStaticParamsType, + GetStaticPaths, +} from "astro"; + +export const getStaticPaths = (async () => { + const products = await getCollection("products"); + + return products.map((product) => { + return { + params: { + product: product.id, + }, + props: { + product, + }, + }; + }); +}) satisfies GetStaticPaths; + +type Props = InferGetStaticPropsType; +type Params = InferGetStaticParamsType; + +export const GET: APIRoute = async ({ + params, + props, + locals, +}) => { + const { data } = props.product; + + const notes = await getChangelogs({ + filter: (e) => { + return e.data.products.some(({ id }) => id === params.product); + }, + }); + + const items = await getRSSItems({ + notes, + locals, + }); + + return rss({ + title: `Cloudflare changelogs | ${data.name}`, + description: `Cloudflare changelogs for ${data.name}`, + site: "https://developers.cloudflare.com/changelog/", + items, + }); +};