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
61 changes: 61 additions & 0 deletions src/pages/changelog/rss/[area].xml.ts
Original file line number Diff line number Diff line change
@@ -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<typeof getStaticPaths>;
type Params = InferGetStaticParamsType<typeof getStaticPaths>;

export const GET: APIRoute<Props, Params> = 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,
});
};
54 changes: 54 additions & 0 deletions src/pages/changelog/rss/[product].xml.ts
Original file line number Diff line number Diff line change
@@ -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<typeof getStaticPaths>;
type Params = InferGetStaticParamsType<typeof getStaticPaths>;

export const GET: APIRoute<Props, Params> = 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,
});
};