|
| 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 | +}; |
0 commit comments