Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: provide for level indents in right side TOC #1189

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assets/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ select {
@apply relative block text-redis-pen-600 hover:text-redis-pen-300 -my-0.5 py-1 pl-6 transition-colors leading-6;
}

/* Increase indentation for deeper nested items */
#TableOfContents ul ul a {
@apply pl-10; /* Second level */
}

#TableOfContents a:before {
content: '';
@apply w-1 h-full bg-redis-pencil-250 absolute left-0 top-0 rounded-sm transition;
Expand Down
20 changes: 16 additions & 4 deletions layouts/partials/docs-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@
<h1 class="font-medium my-3">On this page</h1>
<nav class="text-slate-700">
<nav id="TableOfContents">
<ul>
{{ $prevLevel := 1 }}
{{ range $i, $header := $headers }}
{{ $genAnchor := index (split (index (split $header "id=\"") 1) "\"") 0 }}
{{ $anchorID := $genAnchor }}
<li><a href="#{{ $anchorID }}">{{ $header | plainify | safeHTML }}</a></li>
{{end}}
</ul>
{{ $level := index (findRE "<h([1-6])" $header 1) 0 | replaceRE "<h([1-6])" "$1" | int }}
{{ if gt $level $prevLevel }}
<ul>
{{ else if lt $level $prevLevel }}
<!-- Close the previous list(s) if this header is shallower -->
{{ range seq (sub $prevLevel $level) }}</ul></li>{{ end }}
{{ else if gt $i 0 }}
<!-- Close previous list item -->
</li>
{{ end }}
<li><a href="#{{ $anchorID }}">{{ $header | plainify | safeHTML }}</a>
{{ $prevLevel = $level }}
{{ end }}
<!-- Close remaining open lists -->
{{ range seq (sub $prevLevel 1) }}</ul></li>{{ end }}
</nav>
</nav>
<!-- Use Hugo's .TableOfContents by default -->
Expand Down