Skip to content

Commit

Permalink
docs: fix toc (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
jer3m01 authored Mar 5, 2024
1 parent e83cf28 commit 9504100
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apps/docs/src/components/table-of-contents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ function updateHeadings(setter: Setter<TocItem[]>) {
[
...document
.getElementsByTagName("article")[0]
.querySelectorAll("h1, h2, h3, h4, h5, h6"),
.querySelectorAll(
"h1[data-toc], h2[data-toc], h3[data-toc], h4[data-toc], h5[data-toc], h6[data-toc]",
),
].map((element) => ({
depth: Number(element.tagName.substr(1)),
text: element.textContent!,
Expand Down
17 changes: 16 additions & 1 deletion apps/docs/src/mdx-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,27 @@ export const mdxComponents = {
const [local, others] = splitProps(props, ["children"]);

return (
<h1 {...others}>
<h1 data-toc="" {...others}>
<MetaTitle>{`${local.children} – Kobalte`}</MetaTitle>
{local.children}
</h1>
);
},
h2: (props: ComponentProps<"h2">) => {
return <h2 data-toc="" {...props} />;
},
h3: (props: ComponentProps<"h3">) => {
return <h3 data-toc="" {...props} />;
},
h4: (props: ComponentProps<"h4">) => {
return <h4 data-toc="" {...props} />;
},
h5: (props: ComponentProps<"h5">) => {
return <h5 data-toc="" {...props} />;
},
h6: (props: ComponentProps<"h6">) => {
return <h6 data-toc="" {...props} />;
},
code: (props: ComponentProps<"code">) => {
const [local, others] = splitProps(props, ["class"]);

Expand Down

0 comments on commit 9504100

Please sign in to comment.