Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"fast-xml-parser": "5.2.0",
"github-slugger": "2.0.0",
"globals": "16.0.0",
"hast-util-heading-rank": "3.0.0",
"hast-util-select": "6.0.4",
"hastscript": "9.0.1",
"he": "1.2.0",
Expand Down
12 changes: 7 additions & 5 deletions src/pages/changelog/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import StarlightPage, {
type StarlightPageProps,
} from "@astrojs/starlight/components/StarlightPage.astro";
import { render } from "astro:content";

import Header from "~/components/changelog/Header.astro";
import ProductPills from "~/components/changelog/ProductPills.astro";
Expand All @@ -11,6 +10,10 @@ import { Steps } from "~/components";
import { format } from "date-fns";
import { getChangelogs } from "~/util/changelog";
import { productsByGroup } from "~/util/products";
import { entryToString } from "~/util/container";
import { process } from "~/util/rehype";

import rehypeShiftHeadings from "~/plugins/rehype/shift-headings.ts";

const notes = await getChangelogs({
filter: (entry) => !entry.data.hidden,
Expand Down Expand Up @@ -42,7 +45,8 @@ const props = {
.map((group) => group[0])
.sort();

const { Content } = await render(entry);
const html = await entryToString(entry, Astro.locals);
const processed = await process(html, [[rehypeShiftHeadings]]);

return (
<div
Expand Down Expand Up @@ -76,9 +80,7 @@ const props = {
</h3>
<ProductPills products={entry.data.products} />
</div>
<p>
<Content />
</p>
<p set:html={processed} />
</li>
</ol>
</Steps>
Expand Down
33 changes: 33 additions & 0 deletions src/plugins/rehype/shift-headings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { headingRank } from "hast-util-heading-rank";
import { visit } from "unist-util-visit";
import type { Root, Element } from "hast";

export default function () {
return function (tree: Root) {
visit(tree, "element", function (element) {
const classNames = (element.properties.className as string[]) ?? [];

if (classNames.includes("heading-wrapper")) {
const heading = element.children.find(
(el) => el.type === "element" && headingRank(el),
) as Element | undefined;

if (heading) {
let level = headingRank(heading);

if (level && level < 4) {
const index = classNames.indexOf(`level-h${level}`);

level = 4;
element.children[element.children.indexOf(heading)] = {
...heading,
tagName: "h" + (level > 6 ? 6 : level < 1 ? 1 : level),
};

classNames[index] = `level-h${level}`;
}
}
}
});
};
}