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-06-04 18:14:02 +0300
committeramazingrise <8315221+AmazingRise@users.noreply.github.com>2020-06-04 18:14:02 +0300
commit7980b976cfc62ab3ed1c852c47ea00b112f01b63 (patch)
treea1a283fb091d335f751887a6746cbf95b329d9ee /layouts
parentdbe3f9a9ebf7900f7c745eb6262b95c5c307fcc6 (diff)
parentecc7086da523397834a054cf5235cf7084b64f1e (diff)
Merge branch 'testing' with ToC collapse feature.
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/head.html14
-rw-r--r--layouts/partials/toc.html31
2 files changed, 26 insertions, 19 deletions
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 773bff3..588d07e 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -40,20 +40,16 @@
loadCSS("https://fonts.googleapis.com/css?family=Lora|Montserrat|Fira+Mono|Noto+Serif+SC|Material+Icons");
</script>
-<script src="{{.Site.BaseURL}}/js/table.js"></script>
-
{{ if .Params.enableMathJax }}
{{ partial "mathjax.html" . }}
{{ end }}
{{ if and (not (.Params.disableToC) ) (.IsPage) }}
-<script src="{{.Site.BaseURL}}/js/toc.js"></script>
-{{ else }}
-<style>
- .toc{
- display: none !important;
- }
-</style>
+ {{ if .Params.disableAutoCollapse }}
+ <script src="{{.Site.BaseURL}}/js/toc.js"></script>
+ {{ else }}
+ <script src="{{.Site.BaseURL}}/js/toc-collapse.js"></script>
+ {{ end }}
{{ end }}
{{ if and (.Site.Params.enableGitalk) (.IsPage) }}
diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html
index a21fa69..667b12c 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 }}" 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 }}