hugo/docs/layouts/_partials/layouts/toc.html
Bjørn Erik Pedersen 61a286595e
Some checks are pending
Test / test (1.23.x, ubuntu-latest) (push) Waiting to run
Test / test (1.23.x, windows-latest) (push) Waiting to run
Test / test (1.24.x, ubuntu-latest) (push) Waiting to run
Test / test (1.24.x, windows-latest) (push) Waiting to run
Merge commit 'b3d87dd0fd'
2025-04-24 10:23:16 +02:00

46 lines
1.3 KiB
HTML

{{ with .Fragments }}
{{ with .Headings }}
<div
x-data="toc"
class="sticky top-[8rem] h-screen overflow-y-auto overflow-x-hidden">
<h2
class="text-base font-semibold tracking-tight text-gray-600 dark:text-gray-400">
On this page
</h2>
<nav class="w-56 mt-2">
<ul>
{{ template "render-toc-level" (dict "h" . "p" $) }}
</ul>
</nav>
</div>
{{ end }}
{{ end }}
{{ define "render-toc-level" }}
{{ range .h }}
{{ if and .ID (and (ge .Level 2) (le .Level 4)) }}
{{ $indentation := "ml-0" }}
{{ if eq .Level 3 }}
{{ $indentation = "ml-2 lg:ml-3" }}
{{ else if eq .Level 4 }}
{{ $indentation = "ml-4 lg:ml-6" }}
{{ end }}
{{ $.p.Store.Set "hasToc" true }}
<li>
<a
href="#{{ .ID }}"
x-ref="{{ .ID }}"
@click.stop="setActive('{{ .ID }}')"
class="block pb-1 text-blue-600 hover:text-blue-500 dark:text-blue-500 dark:hover:text-blue-400 text-sm {{ $indentation }}"
:class="{'font-bold dark:text-blue-200 dark:hover:text-blue-300' : activeHeading === '{{ .ID }}'}">
{{ .Title | safeHTML }}
</a>
</li>
{{ end }}
{{ with .Headings }}
<ul>
{{ template "render-toc-level" (dict "h" . "p" $.p) }}
</ul>
{{ end }}
{{ end }}
{{ end }}