début de mise en place de la toc. le design reste à voir
This commit is contained in:
parent
e210ed40f6
commit
0de3b29e8b
7 changed files with 44 additions and 2 deletions
|
|
@ -29,7 +29,8 @@ h5,
|
||||||
h5 *,
|
h5 *,
|
||||||
p,
|
p,
|
||||||
p *:not(strong),
|
p *:not(strong),
|
||||||
figcaption {
|
figcaption,
|
||||||
|
.toc{
|
||||||
font-weight: var(--font-weight-light);
|
font-weight: var(--font-weight-light);
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
assets/css/src/toc.css
Normal file
15
assets/css/src/toc.css
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
.page-cover .toc{
|
||||||
|
position: fixed;
|
||||||
|
display: block;
|
||||||
|
width: calc(var(--body-padding) - var(--unit--horizontal) * 2) ;
|
||||||
|
left: 0;
|
||||||
|
top: 15vw;
|
||||||
|
padding-inline: var(--unit--horizontal);
|
||||||
|
}
|
||||||
|
.toc_label{
|
||||||
|
font-size: var(--font-size-m);
|
||||||
|
}
|
||||||
|
.toc li{
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
@import url("src/footer.css");
|
@import url("src/footer.css");
|
||||||
@import url("src/toggle-light-mode.css");
|
@import url("src/toggle-light-mode.css");
|
||||||
@import url("src/print.css");
|
@import url("src/print.css");
|
||||||
|
@import url("src/toc.css");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,14 @@ function allYears ($article) {
|
||||||
return $years;
|
return $years;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addAnchors($content) {
|
||||||
|
$content = preg_replace_callback('/<h3>(.*?)<\/h3>/', function($matches) {
|
||||||
|
$slug = Str::slug($matches[1]);
|
||||||
|
return '<h3 id="' . $slug . '">' . $matches[1] . '</h3>';
|
||||||
|
}, $content);
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
function setTitleFontSizeClass($title, $level = 'h1')
|
function setTitleFontSizeClass($title, $level = 'h1')
|
||||||
{
|
{
|
||||||
$length = strlen($title);
|
$length = strlen($title);
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ $isOpen ??= false;
|
||||||
<?= $slots->title() ?>
|
<?= $slots->title() ?>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<?php if ($page->parent()->parent()->is('textes')){
|
||||||
|
snippet('toc', ["content" => $page->bodyBlocks()->toBlocks()]);
|
||||||
|
} ?>
|
||||||
<?php if ($slots->text()): ?>
|
<?php if ($slots->text()): ?>
|
||||||
<div class="text-wrapper">
|
<div class="text-wrapper">
|
||||||
<?= $slots->text() ?>
|
<?= $slots->text() ?>
|
||||||
|
|
|
||||||
13
site/snippets/toc.php
Normal file
13
site/snippets/toc.php
Normal 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>
|
||||||
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
<?php endslot() ?>
|
<?php endslot() ?>
|
||||||
<?php endsnippet() ?>
|
<?php endsnippet() ?>
|
||||||
|
|
||||||
|
|
||||||
<div id="main-content">
|
<div id="main-content">
|
||||||
<?php if ($page->chapo()->isNotEmpty()): ?>
|
<?php if ($page->chapo()->isNotEmpty()): ?>
|
||||||
<div id="chapo">
|
<div id="chapo">
|
||||||
|
|
@ -33,7 +34,7 @@
|
||||||
<?php if ($page->isHtmlMode()->isTrue()): ?>
|
<?php if ($page->isHtmlMode()->isTrue()): ?>
|
||||||
<?= $page->htmlBody()->kt() ?>
|
<?= $page->htmlBody()->kt() ?>
|
||||||
<?php elseif ($page->bodyBlocks()->isNotEmpty()): ?>
|
<?php elseif ($page->bodyBlocks()->isNotEmpty()): ?>
|
||||||
<?= $page->bodyBlocks()->toBlocks() ?>
|
<?= addAnchors($page->bodyBlocks()->toBlocks()) ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?= $page->body() ?>
|
<?= $page->body() ?>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue