|
1 | | ---- |
2 | | -import { getEntry, type CollectionEntry } from "astro:content"; |
3 | | -import { marked } from "marked"; |
| 1 | +<!-- --- |
4 | 2 | import { getChangelogs } from "~/util/changelogs"; |
5 | | -import AnchorHeading from "~/components/AnchorHeading.astro"; |
6 | | -import { entryToString } from "~/util/container"; |
| 3 | +import { getEntry } from "astro:content"; |
7 | 4 |
|
8 | 5 | const page = await getEntry("docs", Astro.params.slug!); |
9 | 6 |
|
10 | 7 | if (!page) { |
11 | 8 | throw new Error( |
12 | | - `[ProductChangelog] Failed to find entry for ${Astro.params.slug}.`, |
| 9 | + `[ProductChangelog] Unable to find entry for ${Astro.params.slug}`, |
13 | 10 | ); |
14 | 11 | } |
15 | 12 |
|
16 | | -if (!page.data.changelog_file_name && !page.data.changelog_product_area_name) { |
17 | | - throw new Error( |
18 | | - `[ProductChangelog] ${Astro.params.slug} does not have a 'changelog_file_name' or 'changaelog_product_area_name' frontmatter property.`, |
19 | | - ); |
20 | | -} |
| 13 | +const { changelog } = page.data; |
21 | 14 |
|
22 | | -if (page.data.changelog_file_name && page.data.changelog_file_name.length > 1) { |
| 15 | +if (!changelog || !changelog.products) { |
23 | 16 | throw new Error( |
24 | | - `[ProductChangelog] This component cannot be used on files that have more than 1 entry in their 'changelog_file_name' frontmatter property.`, |
| 17 | + `[ProductChangelog] ${Astro.params.slug} must have a "changelog" entry in frontmatter`, |
25 | 18 | ); |
26 | 19 | } |
27 | 20 |
|
28 | | -const name = |
29 | | - page.data.changelog_product_area_name ?? page.data.changelog_file_name?.[0]; |
30 | | -
|
31 | | -let changelogs; |
32 | | -
|
33 | | -if (page.data.changelog_product_area_name) { |
34 | | - const opts = { |
35 | | - filter: (entry: CollectionEntry<"changelogs">) => { |
36 | | - return entry.data.productArea === name; |
37 | | - }, |
38 | | - }; |
39 | | - ({ changelogs } = await getChangelogs(opts)); |
40 | | -} else { |
41 | | - if (name === "wrangler") { |
42 | | - const opts = { |
43 | | - wranglerOnly: true, |
44 | | - }; |
45 | | - ({ changelogs } = await getChangelogs(opts)); |
46 | | - } else if (name === "api-deprecations") { |
47 | | - const opts = { |
48 | | - deprecationsOnly: true, |
49 | | - }; |
50 | | - ({ changelogs } = await getChangelogs(opts)); |
51 | | - } else { |
52 | | - const opts = { |
53 | | - filter: (entry: CollectionEntry<"changelogs">) => { |
54 | | - return entry.id === name; |
55 | | - }, |
56 | | - }; |
57 | | - ({ changelogs } = await getChangelogs(opts)); |
58 | | - } |
59 | | -} |
60 | | -
|
61 | | -if (!changelogs) { |
62 | | - throw new Error( |
63 | | - `[ProductChangelog] Failed to find changelog called ${name}.`, |
64 | | - ); |
65 | | -} |
| 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 | +}); |
66 | 28 | --- |
67 | 29 |
|
68 | 30 | { |
69 | | - page.data.pcx_content_type === "changelog" && ( |
70 | | - <p> |
71 | | - <a href={`/${page.id}/index.xml`} target="_blank"> |
72 | | - Subscribe to RSS |
73 | | - </a> |
74 | | - </p> |
75 | | - ) |
76 | | -} |
77 | | -{ |
78 | | - changelogs.map(([date, entries]) => ( |
79 | | - <div data-date={date}> |
80 | | - {(entries ?? []).map(async (entry) => { |
81 | | - let description; |
82 | | - if (entry.individual_page) { |
83 | | - const link = entry.individual_page; |
84 | | - |
85 | | - if (!link) |
86 | | - throw new Error( |
87 | | - `Changelog entry points to individual page but no link is provided`, |
88 | | - ); |
89 | | - |
90 | | - const page = await getEntry("docs", link.slice(1, -1)); |
91 | | - |
92 | | - if (!page) |
93 | | - throw new Error( |
94 | | - `Changelog entry points to ${link.slice(1, -1)} but unable to find entry with that slug`, |
95 | | - ); |
96 | | - |
97 | | - description = (await entryToString(page, Astro.locals)) ?? page.body; |
98 | | - |
99 | | - return ( |
100 | | - <div data-product={entry.product.toLowerCase()}> |
101 | | - <a href={entry.individual_page} class="no-underline"> |
102 | | - <AnchorHeading depth={2} title={page.data.title} /> |
103 | | - </a> |
104 | | - <p class="text-xs">{entry.date}</p> |
105 | | - {page.data.changelog_product_area_name && ( |
106 | | - <h3 class="!mt-4"> |
107 | | - <a href={entry.productLink}>{entry.product}</a> |
108 | | - </h3> |
109 | | - )} |
110 | | - {<Fragment set:html={description} />} |
111 | | - </div> |
112 | | - ); |
113 | | - } else { |
114 | | - description = marked.parse(entry.description as string); |
115 | | - return ( |
116 | | - <> |
117 | | - <AnchorHeading depth={2} title={date} /> |
118 | | - <div data-product={entry.product.toLowerCase()}> |
119 | | - {page.data.changelog_product_area_name && ( |
120 | | - <h3 class="!mt-4"> |
121 | | - <a href={entry.productLink}>{entry.product}</a> |
122 | | - </h3> |
123 | | - )} |
124 | | - {entry.title && <strong>{entry.title}</strong>} |
125 | | - {<Fragment set:html={description} />} |
126 | | - </div> |
127 | | - </> |
128 | | - ); |
129 | | - } |
130 | | - })} |
131 | | - </div> |
| 31 | + changelogs.map((entry) => ( |
| 32 | + <h3>{entry.data.date.toISOString().slice(0, 10)}</h3> |
| 33 | + <h4>{entry.data.description}</h4> |
| 34 | + <p>For more information, refer to the <a href={entry.data.link}>dedicated changelog post</a>.</p> |
132 | 35 | )) |
133 | | -} |
| 36 | +} --> |
0 commit comments