1
1
< section class ="tree-menu ">
2
- < input type ="text " name ="filter " data-tree-filter placeholder ="Filter links " />
3
- < ul class ="tree-root ">
4
- {{- $here := .dir }}
5
- {{- range (readDir $here) }}
6
- {{ if in .Name "image" }}
7
- {{ else }}
8
- {{- $fullPath := (printf "%s%s" $here .Name) }}
9
- {{- $fullUrl := replace $fullPath "/content" "" }}
10
- {{- $stat := os.Stat $fullPath }}
11
- {{ if $stat.IsDir }}
12
- {{- template "treemenu" dict "path" $fullPath "url" $fullUrl "root" $.root "depth" 1 }}
13
- {{ end }}
14
- {{ end }}
15
- {{- end -}}
16
- </ ul >
17
- </ section >
18
- {{ define "treemenu" }}
19
- {{ $nextDepth := add .depth 1 }}
20
- {{- $activeLink := $.root.Permalink }}
21
- {{- $className := "" }}
22
- {{- $deprecated := true }}
23
- {{- with $.root.Site.GetPage .url }}
24
- {{- if not .Params.deprecated }}
25
- {{- $deprecated = false }}
26
- {{- $branchLink := .Permalink }}
27
- {{- if in $activeLink $branchLink }}
28
- {{- $className = "tree-branch-active" -}}
29
- {{ end }}
30
- {{- if eq $activeLink $branchLink }}
31
- {{- $className = "tree-active tree-branch-active" -}}
32
- {{- end -}}
33
- < li data-depth ="{{ $.depth }} " class ="{{ $className }} ">
34
- < a href ="{{ .Permalink }} "> {{ .Title }}</ a >
35
- {{- end }}
36
- {{- end }}
37
- {{- if not $deprecated }}
38
- < ul class ="tree-branch ">
39
- {{- range (readDir .path) }}
40
- {{- if in .Name "image" | or (eq .Name "_index.md") }}
41
- {{- else }}
42
- {{- $fullPath := (printf "%s/%s" $.path .Name) }}
2
+ < input type ="text " name ="filter " data-tree-filter placeholder ="Filter links " />
3
+ < ul class ="tree-root ">
4
+ {{- $here := .dir }}
5
+ {{- range (readDir $here) }}
6
+ {{- if not (in .Name "image") }}
7
+ {{- $fullPath := (printf "%s%s" $here .Name) }}
43
8
{{- $fullUrl := replace $fullPath "/content" "" }}
44
- {{- $fullUrl = replace $fullUrl ".md" "" }}
45
9
{{- $stat := os.Stat $fullPath }}
46
10
{{- if $stat.IsDir }}
47
- {{- template "treemenu" dict "path" $fullPath "url" $fullUrl "root" $.root "depth" $nextDepth }}
48
- {{- else }}
49
- {{- with $.root.Site.GetPage $fullUrl }}
50
- {{- $link := printf "%s" .Permalink }}
51
- < li {{- if in $activeLink $link }} class ="tree-active "{{ end }} >
52
- < a href ="{{ .Permalink }} "> {{ .Title }}</ a >
53
- </ li >
54
- {{- end }}
11
+ {{- template "treemenu" dict "path" $fullPath "url" $fullUrl "root" $.root "depth" 1 }}
55
12
{{- end }}
56
13
{{- end }}
57
14
{{- end }}
58
- </ ul >
59
- </ li >
60
- {{- end }}
61
- {{ end }}
15
+ </ ul >
16
+ </ section >
17
+
18
+ {{ define "treemenu" }}
19
+ {{ $nextDepth := add .depth 1 }}
20
+ {{ $activeLink := $.root.Permalink }}
21
+ {{ $className := "" }}
22
+ {{ $deprecated := true }}
23
+ {{ with $.root.Site.GetPage .url }}
24
+ {{ if not .Params.deprecated }}
25
+ {{ $deprecated = false }}
26
+ {{ $branchLink := .Permalink }}
27
+ {{ if in $activeLink $branchLink }}
28
+ {{ $className = "tree-branch-active" }}
29
+ {{ end }}
30
+ {{ if eq $activeLink $branchLink }}
31
+ {{ $className = "tree-active tree-branch-active" }}
32
+ {{ end }}
33
+ < li data-depth ="{{ $.depth }} " class ="{{ $className }} ">
34
+ < a href ="{{ .Permalink }} " data-toggle ="tree-branch "> {{ .Title }}</ a >
35
+ {{ if lt $.depth 3 }}
36
+ < ul class ="tree-branch " style ="display:none; ">
37
+ {{ range (readDir $.path) }}
38
+ {{ if not (in .Name "image" | or (eq .Name "_index.md")) }}
39
+ {{ $fullPath := printf "%s/%s" $.path .Name }}
40
+ {{ $fullUrl := replace $fullPath "/content" "" }}
41
+ {{ $fullUrl = replace $fullUrl ".md" "" }}
42
+ {{ $stat := os.Stat $fullPath }}
43
+ {{ if $stat.IsDir }}
44
+ {{ template "treemenu" dict "path" $fullPath "url" $fullUrl "root" $.root "depth" $nextDepth }}
45
+ {{ else }}
46
+ {{ with $.root.Site.GetPage $fullUrl }}
47
+ {{ $link := printf "%s" .Permalink }}
48
+ < li {{ if in $activeLink $link }} class ="tree-active "{{ end }} >
49
+ < a href ="{{ .Permalink }} "> {{ .Title }}</ a >
50
+ </ li >
51
+ {{ end }}
52
+ {{ end }}
53
+ {{ end }}
54
+ {{ end }}
55
+ </ ul >
56
+ {{ end }}
57
+ </ li >
58
+ {{ end }}
59
+ {{ end }}
60
+ {{ end }}
61
+ < script >
62
+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
63
+ const toggles = document . querySelectorAll ( '[data-toggle="tree-branch"]' ) ;
64
+
65
+ toggles . forEach ( function ( toggle ) {
66
+ toggle . addEventListener ( "mouseover" , function ( event ) {
67
+ const branch = this . nextElementSibling ;
68
+ if ( branch && branch . classList . contains ( 'tree-branch' ) ) {
69
+ branch . style . display = "block" ;
70
+ }
71
+ } ) ;
72
+
73
+ toggle . parentElement . addEventListener ( "mouseleave" , function ( event ) {
74
+ const branch = toggle . nextElementSibling ;
75
+ if ( branch && branch . classList . contains ( 'tree-branch' ) ) {
76
+ branch . style . display = "block" ;
77
+ }
78
+ } ) ;
79
+ } ) ;
80
+ } ) ;
81
+ </ script >
0 commit comments