Skip to content

Commit d76adb1

Browse files
authored
[Docs Site] Remove Container API usage from changelog (#22591)
* [Docs Site] Remove Container API usage from changelog * dont use style prop
1 parent 8aca7ac commit d76adb1

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

astro.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import rehypeMermaid from "./src/plugins/rehype/mermaid.ts";
1616
import rehypeAutolinkHeadings from "./src/plugins/rehype/autolink-headings.ts";
1717
import rehypeExternalLinks from "./src/plugins/rehype/external-links.ts";
1818
import rehypeHeadingSlugs from "./src/plugins/rehype/heading-slugs.ts";
19+
import rehypeShiftHeadings from "./src/plugins/rehype/shift-headings.ts";
1920

2021
async function autogenSections() {
2122
const sections = (
@@ -67,6 +68,7 @@ export default defineConfig({
6768
rehypeAutolinkHeadings,
6869
// @ts-expect-error plugins types are outdated but functional
6970
rehypeTitleFigure,
71+
rehypeShiftHeadings,
7072
],
7173
},
7274
image: {

src/pages/changelog/index.astro

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import { Steps } from "~/components";
1010
import { format } from "date-fns";
1111
import { getChangelogs } from "~/util/changelog";
1212
import { productsByGroup } from "~/util/products";
13-
import { entryToString } from "~/util/container";
14-
import { process } from "~/util/rehype";
1513
16-
import rehypeShiftHeadings from "~/plugins/rehype/shift-headings.ts";
14+
import { render } from "astro:content";
1715
1816
const notes = await getChangelogs({
1917
filter: (entry) => !entry.data.hidden,
@@ -45,24 +43,22 @@ const props = {
4543
.map((group) => group[0])
4644
.sort();
4745

48-
const html = await entryToString(entry, Astro.locals);
49-
const processed = await process(html, [[rehypeShiftHeadings]]);
46+
const { Content } = await render(entry);
5047

5148
return (
5249
<div
53-
class="mt-0! sm:flex"
50+
class:list={["mt-0! sm:flex", { "hidden!": idx >= 10 }]}
5451
data-products={JSON.stringify(
5552
productIds.concat(
5653
productGroups.map((group) =>
5754
group.replaceAll(" ", "-").toLowerCase(),
5855
),
5956
),
6057
)}
61-
style={`display: ${idx >= 10 ? "none" : ""}`}
6258
>
6359
<time
6460
datetime={entry.data.date.toISOString()}
65-
class="whitespace-nowrap text-xs font-bold leading-6 sm:pr-4 sm:text-right"
61+
class="text-xs leading-6 font-bold whitespace-nowrap sm:pr-4 sm:text-right"
6662
>
6763
{date}
6864
</time>
@@ -80,7 +76,7 @@ const props = {
8076
</h3>
8177
<ProductPills products={entry.data.products} />
8278
</div>
83-
<p set:html={processed} />
79+
<Content />
8480
</li>
8581
</ol>
8682
</Steps>
@@ -91,7 +87,7 @@ const props = {
9187
<div class="flex items-center justify-center">
9288
<button
9389
id="changelogs-next-button"
94-
class="h-12 cursor-pointer rounded-sm bg-cl1-brand-orange px-6 font-medium text-cl1-black"
90+
class="bg-cl1-brand-orange text-cl1-black h-12 cursor-pointer rounded-sm px-6 font-medium"
9591
>
9692
Load more items
9793
</button>
@@ -134,11 +130,12 @@ const props = {
134130
...document.querySelectorAll<HTMLElement>("[data-products]"),
135131
]
136132
.filter(
137-
(e) => e.style.display === "none" && filterByProduct(e, filter!.value),
133+
(e) =>
134+
e.classList.contains("hidden!") && filterByProduct(e, filter!.value),
138135
)
139136
.slice(0, 10);
140137

141-
hidden.forEach((e) => (e.style.display = ""));
138+
hidden.forEach((e) => e.classList.remove("hidden!"));
142139

143140
hideButton();
144141
});
@@ -160,9 +157,9 @@ const props = {
160157
const show = filtered.includes(entry);
161158

162159
if (show) {
163-
entry.style.display = "";
160+
entry.classList.remove("hidden!");
164161
} else {
165-
entry.style.display = "none";
162+
entry.classList.add("hidden!");
166163
}
167164
}
168165

@@ -188,13 +185,13 @@ const props = {
188185

189186
const filtered = entries.filter((p) => filterByProduct(p, filter!.value));
190187

191-
const visible = filtered.filter((p) => p.style.display !== "none");
188+
const visible = filtered.filter((p) => !p.classList.contains("hidden!"));
192189
const hidden = filtered.length - visible.length;
193190

194191
if (hidden > 0) {
195-
button!.style.display = "";
192+
button!.classList.remove("hidden!");
196193
} else {
197-
button!.style.display = "none";
194+
button!.classList.add("hidden!");
198195
}
199196
}
200197
</script>

src/plugins/rehype/shift-headings.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ import { visit } from "unist-util-visit";
33
import type { Root, Element } from "hast";
44

55
export default function () {
6-
return function (tree: Root) {
6+
return function (tree: Root, file: any) {
77
visit(tree, "element", function (element) {
8+
if (
9+
!file.history.find((path: string) =>
10+
path.includes("/src/content/changelog/"),
11+
)
12+
) {
13+
return;
14+
}
15+
816
const classNames = (element.properties.className as string[]) ?? [];
917

1018
if (classNames.includes("heading-wrapper")) {

0 commit comments

Comments
 (0)