Skip to content

Commit

Permalink
Moves heading check logic into the TableOfContents component
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerchew committed Jan 8, 2025
1 parent 1982963 commit 6cce883
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/components/TableOfContents.astro
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ interface Props {
}
const { headings } = Astro.props;
const showTOC = headings && headings.length > 2;
---

{
headings?.length && (
showTOC && (
<nav class="toc" aria-labelledby="tocHeader">
<h2 class="toc-header" id="tocHeader">
On this page
Expand Down
3 changes: 1 addition & 2 deletions src/layouts/ProseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const {
color,
headings,
} = Astro.props;
const useTableOfContents = headings && headings.length > 0;
---

<BaseLayout
Expand All @@ -50,7 +49,7 @@ const useTableOfContents = headings && headings.length > 0;
annotation={annotation}
/>
<slot name="after-header" />
{useTableOfContents && <TableOfContents headings={headings} />}
<TableOfContents headings={headings} />
<section itemprop="articleBody" class="prose">
<slot />
</section>
Expand Down

0 comments on commit 6cce883

Please sign in to comment.