/
toc.php
40 lines (29 loc) · 907 Bytes
/
toc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
$Page = $Automad->Context->get();
$main = json_decode($Page->get('+main'));
$output = '';
if (!empty($main) && !empty($main->blocks)) {
foreach($main->blocks as $block) {
if (($block->type == 'header') && isset($block->data->level) && ($block->data->level >= 2) && ($block->data->level <= 3)) {
$id = Automad\Core\Str::sanitize($block->data->text, true);
$padding = strval((intval($block->data->level) * 15) - 25);
$output .= <<< HTML
<a href="#$id" class="sidebar-link pl-{$padding}">
<span>{$block->data->text}</span>
</a>
HTML;
}
}
}
if ($output) { ?>
<div class="ml-20 sidebar-menu">
<div class="position-sticky top-0">
<div class="font-weight-medium pb-20">
@{ tableOfContentsTitle | def ('On this page') }
</div>
<div class="border-left pl-10 d-flex flex-column">
<?php echo $output; ?>
</div>
</div>
</div>
<?php } ?>