|
1 | 1 | <!-- --- |
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"; |
4 | 6 |
|
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 | +})); |
6 | 12 |
|
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"]; |
12 | 16 |
|
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 | + }); |
14 | 25 |
|
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 | + } |
19 | 29 | } |
20 | 30 |
|
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 }); |
28 | 32 | --- |
29 | 33 |
|
30 | 34 | { |
|
0 commit comments