Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/AmazingRise/hugo-theme-diary.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramazingrise <8315221+AmazingRise@users.noreply.github.com>2020-05-24 20:22:20 +0300
committeramazingrise <8315221+AmazingRise@users.noreply.github.com>2020-05-24 20:22:20 +0300
commitfe503379b2e9930459d75096f7bed0e0cfbaf334 (patch)
tree737ad073282c3a8bda63cc632f59e59bd6f7b007 /layouts
parentb4c734f9d845231025817c5fe661b940dae81ec2 (diff)
Finish auto collapse on contents.
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/toc.html31
1 files changed, 21 insertions, 10 deletions
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html
index a21fa69..4f4a79c 100644
--- a/layouts/partials/toc.html
+++ b/layouts/partials/toc.html
@@ -7,25 +7,36 @@
{{ $re := (cond (eq $h1_n 0) "<h[2-4]" "<h[1-4]") }}
{{ $renum := (cond (eq $h1_n 0) "[2-4]" "[1-4]") }}
<center>- {{ i18n "toc_title" }} -</center>
+ {{ $scratch := newScratch }}
+ {{ $scratch.Set "prev_heading" 1 }}
+ <ul>
{{ range $headers }}
{{ $header := . }}
{{ range first 1 (findRE $re $header 1) }}
{{ range findRE $renum . 1 }}
{{ $next_heading := (cond (eq $h1_n 0) (sub (int .) 1 ) (int . ) ) }}
- {{ range seq $next_heading }}
- <ul>
+ {{ $prev_heading := $scratch.Get "prev_heading"}}
+ {{ if lt $next_heading $prev_heading }}
+ {{ range seq (sub $prev_heading $next_heading) }}
+ </ul>
+ {{ end }}
{{ end }}
- {{ $anchorId := (replaceRE ".* id=\"(.*?)\".*" "$1" $header ) }}
- <li>
- <a href="#{{ $anchorId }}" v-on:click="closeDrawer" id="{{ $anchorId }}-nav">
- {{ $header | plainify | htmlUnescape }}
- </a>
- </li>
- {{ range seq $next_heading }}
- </ul>
+ {{ if gt $next_heading $prev_heading }}
+ {{ range seq (sub $next_heading $prev_heading) }}
+ <ul class="collapse" data-toggle="collapse">
+ {{ end }}
{{ end }}
+ {{ $anchorId := (replaceRE ".* id=\"(.*?)\".*" "$1" $header ) }}
+ <li>
+ <a href="#{{ $anchorId }}" v-on:click="closeDrawer" onclick="collapseOthers(`#{{ $anchorId | safeJS}}-nav`)" id="{{ $anchorId }}-nav">
+ {{ $header | plainify | htmlUnescape }}
+ </a>
+ </li>
+
+ {{ $scratch.Set "prev_heading" $next_heading }}
{{ end }}
{{ end }}
{{ end }}
+ </ul>
</div>
{{ end }}