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

toc.html « partials « layouts - github.com/AmazingRise/hugo-theme-diary.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 667b12c2cc46a8f28579f04921d117892ad69b63 (plain)
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
41
42
{{ $headers := findRE "<h[1-4].*?>(.|\n])+?</h[1-4]>" .Content }}
<!-- at least one header to link to -->
{{ if ge (len $headers) 1 }}
	<div class="toc-content">
	<!-- ignore empty links with + -->
		{{ $h1_n := len (findRE "(.|\n])+?" .Content) }}
		{{ $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 . ) ) }}
						{{ $prev_heading := $scratch.Get "prev_heading"}}
						{{ if lt $next_heading $prev_heading }}
							{{ range seq (sub $prev_heading $next_heading) }}
								</ul>
							{{ end }}
						{{ end }}
						{{ 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 }}