Skip to content

Commit 598fdf7

Browse files
committed
[Docs Site] Support individual pages in ProductChangelog component
1 parent 082682c commit 598fdf7

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

src/components/ProductChangelog.astro

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getEntry, type CollectionEntry } from "astro:content";
33
import { marked } from "marked";
44
import { getChangelogs } from "~/util/changelogs";
55
import AnchorHeading from "~/components/AnchorHeading.astro";
6+
import { entryToString } from "~/util/container";
67
78
const page = await getEntry("docs", Astro.params.slug!);
89
@@ -62,18 +63,55 @@ if (!changelogs) {
6263
{
6364
changelogs.map(([date, entries]) => (
6465
<div data-date={date}>
65-
<AnchorHeading depth={2} title={date} />
66-
{(entries ?? []).map((entry) => (
67-
<div data-product={entry.product.toLowerCase()}>
68-
{page.data.changelog_product_area_name && (
69-
<h3 class="!mt-4">
70-
<a href={entry.productLink}>{entry.product}</a>
71-
</h3>
72-
)}
73-
{entry.title && <strong>{entry.title}</strong>}
74-
<Fragment set:html={marked.parse(entry.description ?? "")} />
75-
</div>
76-
))}
66+
{(entries ?? []).map(async (entry) => {
67+
let description;
68+
if (entry.individual_page) {
69+
const link = entry.individual_page;
70+
71+
if (!link)
72+
throw new Error(
73+
`Changelog entry points to individual page but no link is provided`,
74+
);
75+
76+
const page = await getEntry("docs", link.slice(1, -1));
77+
78+
if (!page)
79+
throw new Error(
80+
`Changelog entry points to ${link.slice(1, -1)} but unable to find entry with that slug`,
81+
);
82+
83+
description = (await entryToString(page)) ?? page.body;
84+
85+
return (
86+
<div data-product={entry.product.toLowerCase()}>
87+
<a href={entry.individual_page} class="no-underline">
88+
<strong>{page.data.title}</strong>
89+
</a>
90+
<p class="text-xs">{entry.date}</p>
91+
{page.data.changelog_product_area_name && (
92+
<h3 class="!mt-4">
93+
<a href={entry.productLink}>{entry.product}</a>
94+
</h3>
95+
)}
96+
{<Fragment set:html={description} />}
97+
</div>
98+
);
99+
} else {
100+
description = marked.parse(entry.description);
101+
return (
102+
<AnchorHeading depth={2} title={date} />
103+
<div data-product={entry.product.toLowerCase()}>
104+
{page.data.changelog_product_area_name && (
105+
<h3 class="!mt-4">
106+
<a href={entry.productLink}>{entry.product}</a>
107+
</h3>
108+
)}
109+
{entry.title && <strong>{entry.title}</strong>}
110+
{<Fragment set:html={description} />}
111+
</div>
112+
);
113+
}
114+
})}
77115
</div>
78116
))
79117
}

src/content/changelogs/workers.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ entries:
1111
- publish_date: "2024-09-19"
1212
description: |-
1313
- Revamped Workers and Pages UI settings to simplify the creation and management of project configurations. For bugs and general feedback, please submit this [form](https://forms.gle/XXqhRGbZmuzninuN9).
14-
- publish_date: '2024-09-16'
14+
- publish_date: "2024-09-16"
1515
description: |-
1616
- Updated v8 to version 12.9.
1717
- publish_date: "2024-08-19"

src/util/changelogs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export async function getChangelogs(opts?: {
3939
productLink: product.data.productLink,
4040
productAreaName: product.data.productArea,
4141
productAreaLink: product.data.productAreaLink,
42+
individual_page: entry.link,
4243
};
4344
});
4445
});

0 commit comments

Comments
 (0)