début de mise en place de la toc. le design reste à voir

This commit is contained in:
antonin gallon 2026-02-16 16:11:36 +01:00
parent e210ed40f6
commit 0de3b29e8b
7 changed files with 44 additions and 2 deletions

View file

@ -8,6 +8,9 @@ $isOpen ??= false;
<?= $slots->title() ?>
</a>
</div>
<?php if ($page->parent()->parent()->is('textes')){
snippet('toc', ["content" => $page->bodyBlocks()->toBlocks()]);
} ?>
<?php if ($slots->text()): ?>
<div class="text-wrapper">
<?= $slots->text() ?>

13
site/snippets/toc.php Normal file
View file

@ -0,0 +1,13 @@
<nav class="toc">
<div class="light toc_label">Sommaire</div>
<ul>
<?php
preg_match_all('/<h3>(.*?)<\/h3>/', $content, $titres);
foreach ($titres[1] as $index => $titre) {
$slug = Str::slug($titre);
echo '<li><a href="#' . $slug . '">' . $titre . '</a></li>';
}
?>
</ul>
</nav>