Skip to content

Commit 2849d75

Browse files
authored
docs: do not consider the main title as part of ToC (#9699)
This makes sure we don't double show the description of the page when at the top.
1 parent 8120ee4 commit 2849d75

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/components/PageContent/PageContent.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ const suppressTitle = content.suppressTitle;
3232
<header>
3333
<slot name="before-title" />
3434
{!suppressTitle && <h1 class="content-title" id="overview" set:html={title} />}
35-
{!suppressTitle && <h2 class="content-subtitle" set:html={description} />}
35+
{!suppressTitle && (
36+
<h2 class="content-subtitle" data-toc-ignore set:html={description} />
37+
)}
3638
<slot name="after-title" />
3739
</header>
3840
{!suppressTitle && <hr class="divider" />}

src/components/RightSidebar/TableOfContents.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ const TableOfContents = ({ toc = [], labels, isMobile }: Props) => {
8787

8888
const headingsObserver = new IntersectionObserver(setCurrent, observerOptions);
8989

90-
// Observe all the headings in the main page content.
91-
document.querySelectorAll('article :is(h1,h2,h3)').forEach((h) => headingsObserver.observe(h));
90+
// Observe all the headings in the main page content, skipping ones marked to ignore.
91+
document
92+
.querySelectorAll('article :is(h1,h2,h3):not([data-toc-ignore])')
93+
.forEach((h) => headingsObserver.observe(h));
9294

9395
// Stop observing when the component is unmounted.
9496
return () => headingsObserver.disconnect();

0 commit comments

Comments
 (0)