Skip to content

Commit 61657a1

Browse files
committed
update productchangelog props
1 parent 90f1803 commit 61657a1

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

src/components/ProductChangelog.astro

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
<!-- ---
2-
import { getChangelogs } from "~/util/changelogs";
3-
import { getEntry } from "astro:content";
2+
import { getChangelogs, type GetChangelogsOptions } from "~/util/changelogs";
3+
import { getEntries, reference } from "astro:content";
4+
import { z } from "astro:schema";
5+
import { getCollection } from "astro:content";
46
5-
const page = await getEntry("docs", Astro.params.slug!);
7+
const props = z.object({
8+
products: z.array(reference("products")),
9+
}).or(z.object({
10+
area: z.string()
11+
}));
612
7-
if (!page) {
8-
throw new Error(
9-
`[ProductChangelog] Unable to find entry for ${Astro.params.slug}`,
10-
);
11-
}
13+
const input = await props.parseAsync(Astro.props);
14+
15+
let filter: GetChangelogsOptions["filter"];
1216
13-
const { changelog } = page.data;
17+
if ("products" in input) {
18+
filter = (e) => {
19+
return e.data.products.some((x) => input.products.some((y) => x.id === y.id))
20+
}
21+
} else {
22+
const products = await getCollection("products", (e) => {
23+
return e.data.product.group === input.area;
24+
});
1425
15-
if (!changelog || !changelog.products) {
16-
throw new Error(
17-
`[ProductChangelog] ${Astro.params.slug} must have a "changelog" entry in frontmatter`,
18-
);
26+
filter = (e) => {
27+
return e.data.products.some((x) => products.some((y) => x.id === y.id))
28+
}
1929
}
2030
21-
const changelogs = await getChangelogs({
22-
filter: (e) => {
23-
return e.data.products.some((p) =>
24-
changelog.products?.some((v) => v.id === p.id),
25-
);
26-
},
27-
});
31+
const changelogs = await getChangelogs({ filter });
2832
---
2933
3034
{

src/content/docs/workers/platform/changelog/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ This is *different* from [compatibility dates](/workers/configuration/compatibil
1717

1818
{/* <!-- Actual content lives in /src/content/changelogs/workers.yaml. Update the file there for new entries to appear here. For more details, refer to https://developers.cloudflare.com/style-guide/documentation-content-strategy/content-types/changelog/#yaml-file --> */}
1919

20-
<ProductChangelog />
20+
<ProductChangelog area="Developer platform" />

src/util/changelogs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function docsToChangelog({
8080
};
8181
}
8282

83-
type GetChangelogsOptions = {
83+
export type GetChangelogsOptions = {
8484
filter?: (entry: CollectionEntry<"changelogs-next">) => boolean;
8585
};
8686

0 commit comments

Comments
 (0)