Skip to content

Commit f5368b5

Browse files
pascalandyclaude
andauthored
refactor(toc): simplify table of contents component (#53)
- Show only when 4+ H2 headings exist - Remove accordion (always visible) - Use app-prose for consistent styling - Add visible "Table des matières" title - Filter to H2 headings only Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 27e73d6 commit f5368b5

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/components/TableOfContents.astro

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,21 @@ type Props = {
1111
1212
const { headings } = Astro.props;
1313
14-
// Filter to h2 and h3 only
15-
const tocHeadings = headings.filter(h => h.depth >= 2 && h.depth <= 3);
14+
// Filter to h2 only
15+
const tocHeadings = headings.filter(h => h.depth === 2);
1616
---
1717

1818
{
19-
tocHeadings.length > 0 && (
20-
<details class="mt-8 mb-4">
21-
<summary class="cursor-pointer">Table of Contents</summary>
22-
<ul class="mt-2 space-y-1 border border-border/50 bg-(--astro-code-background) p-4 text-muted-foreground">
19+
tocHeadings.length >= 4 && (
20+
<nav aria-label="Table des matières" class="app-prose my-8">
21+
<h2>Table des matières</h2>
22+
<ul class="list-disc pl-4">
2323
{tocHeadings.map(heading => (
24-
<li class:list={[heading.depth === 3 && "ml-4"]}>
25-
<a href={`#${heading.slug}`} class="hover:text-foreground">
26-
{heading.text}
27-
</a>
24+
<li>
25+
<a href={`#${heading.slug}`}>{heading.text}</a>
2826
</li>
2927
))}
3028
</ul>
31-
</details>
29+
</nav>
3230
)
3331
}

0 commit comments

Comments
 (0)