Skip to content

Commit dc8882d

Browse files
authored
Merge pull request #28521 from seokho-son/fixdocsythm
Fix sidebar-tree indentation by updating layout with latest docsy theme
2 parents cafede5 + e26ff03 commit dc8882d

File tree

1 file changed

+70
-41
lines changed

1 file changed

+70
-41
lines changed

layouts/partials/sidebar-tree.html

Lines changed: 70 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,92 @@
11
{{/* We cache this partial for bigger sites and set the active class client side. */}}
2-
{{ $shouldDelayActive := ge (len .Site.Pages) 2000 }}
2+
{{ $sidebarCacheLimit := cond (isset .Site.Params.ui "sidebar_cache_limit") .Site.Params.ui.sidebar_cache_limit 2000 }}
3+
{{ $shouldDelayActive := ge (len .Site.Pages) $sidebarCacheLimit }}
34
<div id="td-sidebar-menu" class="td-sidebar__inner{{ if $shouldDelayActive }} d-none{{ end }}">
45
{{ if not .Site.Params.ui.sidebar_search_disable }}
56
<form class="td-sidebar__search d-flex align-items-center">
67
{{ partial "search-input.html" . }}
78
<button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation">
89
</button>
910
</form>
11+
{{ else }}
12+
<div id="content-mobile">
13+
<form class="td-sidebar__search d-flex align-items-center">
14+
{{ partial "search-input.html" . }}
15+
<button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation">
16+
</button>
17+
</form>
18+
</div>
19+
<div id="content-desktop"></div>
1020
{{ end }}
11-
<nav class="collapse td-sidebar-nav" id="td-section-nav">
21+
<nav class="collapse td-sidebar-nav{{ if .Site.Params.ui.sidebar_menu_foldable }} foldable-nav{{ end }}" id="td-section-nav">
1222
<!-- {{ if (gt (len .Site.Home.Translations) 0) }}
1323
<div class="nav-item dropdown d-block d-lg-none">
1424
{{ partial "navbar-lang-selector.html" . }}
1525
</div>
1626
{{ end }} -->
27+
<!-- {{ $navRoot := cond (and (ne .Params.toc_root true) (eq .Site.Home.Type "docs")) .Site.Home .FirstSection }} -->
28+
{{ $ulNr := 0 }}
29+
{{ $ulShow := cond (isset .Site.Params.ui "ul_show") .Site.Params.ui.ul_show 1 }}
30+
{{ $sidebarMenuTruncate := cond (isset .Site.Params.ui "sidebar_menu_truncate") .Site.Params.ui.sidebar_menu_truncate 50 }}
1731
{{ $currentLang := .Site.Language }}
18-
{{ template "section-tree-nav-section" (dict "page" . "section" .FirstSection "delayActive" $shouldDelayActive "currentLang" $currentLang) }}
32+
<ul class="td-sidebar-nav__section pr-md-3 ul-{{ $ulNr }}">
33+
{{ template "section-tree-nav-section" (dict "page" . "section" $navRoot "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" (add $ulShow 1) "currentLang" $currentLang) }}
34+
</ul>
1935
</nav>
2036
</div>
2137
{{ define "section-tree-nav-section" }}
22-
{{ $s := .section }}
23-
{{ $p := .page }}
24-
{{ $shouldDelayActive := .delayActive }}
25-
{{ $active := eq $p.CurrentSection $s }}
26-
{{ $show := or (eq $s $p.FirstSection) (and (not $p.Site.Params.ui.sidebar_menu_compact) ($p.IsDescendant $s)) }}
27-
{{ $sid := $s.RelPermalink | anchorize }}
28-
<ul class="td-sidebar-nav__section pr-md-3">
29-
{{ if (ne $s.File.Path "docs/_index.md") }}
30-
<li class="td-sidebar-nav__section-title">
31-
<a href="{{ $s.RelPermalink }}" class="align-left pl-0 pr-2{{ if not $show }} collapsed{{ end }}{{ if $active}} active{{ end }} td-sidebar-link td-sidebar-link__section">
32-
{{ $s.LinkTitle }}
33-
</a>
34-
</li>
35-
{{ end }}
36-
<ul>
37-
<li class="collapse {{ if $show }}show{{ end }}" id="{{ $sid }}">
38-
{{ $pages := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true }}
39-
{{ with site.Params.language_alternatives }}
40-
{{ range . }}
41-
{{ with (where $.section.Translations ".Lang" . ) }}
42-
{{ $p := index . 0 }}
43-
{{ $pages = $pages | lang.Merge (union $p.Pages $p.Sections) }}
38+
{{ $s := .section }}
39+
{{ $p := .page }}
40+
{{ $shouldDelayActive := .shouldDelayActive }}
41+
{{ $sidebarMenuTruncate := .sidebarMenuTruncate }}
42+
{{ $treeRoot := cond (eq .ulNr 0) true false }}
43+
{{ $ulNr := .ulNr }}
44+
{{ $ulShow := .ulShow }}
45+
{{ $active := and (not $shouldDelayActive) (eq $s $p) }}
46+
{{ $activePath := and (not $shouldDelayActive) ($p.IsDescendant $s) }}
47+
{{ $show := cond (or (lt $ulNr $ulShow) $activePath (and (not $shouldDelayActive) (eq $s.Parent $p.Parent)) (and (not $shouldDelayActive) (eq $s.Parent $p)) (and (not $shouldDelayActive) ($p.IsDescendant $s.Parent))) true false }}
48+
{{ $mid := printf "m-%s" ($s.RelPermalink | anchorize) }}
49+
{{ $pages_tmp := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true }}
50+
{{ $pages := $pages_tmp | first $sidebarMenuTruncate }}
51+
{{ $withChild := gt (len $pages) 0 }}
52+
{{ $manualLink := cond (isset $s.Params "manuallink") $s.Params.manualLink ( cond (isset $s.Params "manuallinkrelref") (relref $s $s.Params.manualLinkRelref) $s.RelPermalink) }}
53+
{{ $manualLinkTitle := cond (isset $s.Params "manuallinktitle") $s.Params.manualLinkTitle $s.Title }}
54+
55+
<li class="td-sidebar-nav__section-title td-sidebar-nav__section{{ if $withChild }} with-child{{ else }} without-child{{ end }}{{ if $activePath }} active-path{{ end }}{{ if (not (or $show $p.Site.Params.ui.sidebar_menu_foldable )) }} collapse{{ end }}" id="{{ $mid }}-li">
56+
{{ if (and $p.Site.Params.ui.sidebar_menu_foldable (ge $ulNr 1)) }}
57+
<input type="checkbox" id="{{ $mid }}-check"{{ if $activePath}} checked{{ end }}/>
58+
<label for="{{ $mid }}-check"><a href="{{ $manualLink }}"{{ if ne $s.LinkTitle $manualLinkTitle }} title="{{ $manualLinkTitle }}"{{ end }}{{ with $s.Params.manualLinkTarget }} target="{{ . }}"{{ if eq . "_blank" }} rel="noopener"{{ end }}{{ end }} class="align-left pl-0 {{ if $active}} active{{ end }} td-sidebar-link{{ if $s.IsPage }} td-sidebar-link__page{{ else }} td-sidebar-link__section{{ end }}{{ if $treeRoot }} tree-root{{ end }}" id="{{ $mid }}">{{ with $s.Params.Icon}}<i class="{{ . }}"></i>{{ end }}<span class="{{ if $active }}td-sidebar-nav-active-item{{ end }}">{{ $s.LinkTitle }}</span></a></label>
59+
{{ else }}
60+
<a href="{{ $manualLink }}"{{ if ne $s.LinkTitle $manualLinkTitle }} title="{{ $manualLinkTitle }}"{{ end }}{{ with $s.Params.manualLinkTarget }} target="{{ . }}"{{ if eq . "_blank" }} rel="noopener"{{ end }}{{ end }} class="align-left pl-0{{ if $active}} active{{ end }} td-sidebar-link{{ if $s.IsPage }} td-sidebar-link__page{{ else }} td-sidebar-link__section{{ end }}{{ if $treeRoot }} tree-root{{ end }}" id="{{ $mid }}">{{ with $s.Params.Icon}}<i class="{{ . }}"></i>{{ end }}<span class="{{ if $active }}td-sidebar-nav-active-item{{ end }}">{{ $s.LinkTitle }}</span></a>
61+
{{ end }}
62+
{{if $withChild }}
63+
{{ $ulNr := add $ulNr 1 }}
64+
<ul class="ul-{{ $ulNr }}{{ if (gt $ulNr 1)}} foldable{{end}}">
65+
{{ $pages := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true }}
66+
{{ with site.Params.language_alternatives }}
67+
{{ range . }}
68+
{{ with (where $.section.Translations ".Lang" . ) }}
69+
{{ $p := index . 0 }}
70+
{{ $pages = $pages | lang.Merge (union $p.Pages $p.Sections) }}
71+
{{ end }}
4472
{{ end }}
4573
{{ end }}
46-
{{ end }}
47-
{{ $pages := $pages | first 50 }}
48-
{{ range $pages }}
49-
{{ if .IsPage }}
50-
{{ $mid := printf "m-%s" (.RelPermalink | anchorize) }}
51-
{{ $active := eq . $p }}
52-
{{ $isForeignLanguage := (ne (string .Lang) (string $.currentLang)) }}
53-
<a class="td-sidebar-link td-sidebar-link__page {{ if and (not $shouldDelayActive) $active }} active{{ end }}" id="{{ $mid }}" {{ if $isForeignLanguage }}target="_blank"{{ end }} href="{{ .RelPermalink }}">
54-
{{ .LinkTitle }}{{ if $isForeignLanguage }} <small>({{ .Lang | upper }})</small>{{ end }}
55-
</a>
56-
{{ else }}
57-
{{ template "section-tree-nav-section" (dict "page" $p "section" . "currentLang" $.currentLang) }}
74+
{{ $pages := $pages | first 50 }}
75+
{{ range $pages }}
76+
{{ if (not (and (eq $s $p.Site.Home) (eq .Params.toc_root true)) ) }}
77+
{{ $mid := printf "m-%s" (.RelPermalink | anchorize) }}
78+
{{ $active := eq . $p }}
79+
{{ $isForeignLanguage := (ne (string .Lang) (string $.currentLang)) }}
80+
{{ if (and $isForeignLanguage ($p.IsDescendant $s)) }}
81+
<a class="td-sidebar-link td-sidebar-link__page {{ if and (not $shouldDelayActive) $active }} active{{ end }}" id="{{ $mid }}" {{ if $isForeignLanguage }}target="_blank"{{ end }} href="{{ .RelPermalink }}">
82+
{{ .LinkTitle }}{{ if $isForeignLanguage }} <small>({{ .Lang | upper }})</small>{{ end }}
83+
</a>
84+
{{ else }}
85+
{{ template "section-tree-nav-section" (dict "page" $p "section" . "currentLang" $.currentLang "shouldDelayActive" $shouldDelayActive "sidebarMenuTruncate" $sidebarMenuTruncate "ulNr" $ulNr "ulShow" $ulShow) }}
86+
{{ end }}
87+
{{ end }}
5888
{{ end }}
59-
{{ end }}
60-
</li>
61-
</ul>
62-
</ul>
89+
</ul>
90+
{{ end }}
91+
</li>
6392
{{ end }}

0 commit comments

Comments
 (0)