diff --git a/layouts/partials/sidebar-tree.html b/layouts/partials/sidebar-tree.html deleted file mode 100644 index 7fb17ee..0000000 --- a/layouts/partials/sidebar-tree.html +++ /dev/null @@ -1,64 +0,0 @@ - - -{{- define "partials/sidebar/mobile-search" -}} -
- {{- partialCached "search.html" . -}} -
-{{- end -}} - -{{- define "partials/sidebar/link" -}} - {{- $external := strings.HasPrefix .link "http" -}} - {{- $open := .open | default true -}} - - {{- .title -}} - {{- with .context }} - {{- if or .RegularPages .Sections }}{{ partialCached "sidebar/collapsible-button" . }}{{ end -}} - {{ end -}} - -{{- end -}} - -{{- define "partials/sidebar/tree" -}} - {{- if ge .level 4 -}} - {{- return -}} - {{- end -}} - - {{- $context := .context -}} - {{- $page := .page }} - {{- $level := .level -}} - - {{- with $items := union .context.RegularPages .context.Sections -}} - {{- if eq $level 0 -}} - {{- range $items.ByWeight }} -
  • - {{- partial "sidebar/link" (dict "context" . "title" .LinkTitle "link" .RelPermalink) -}} - {{- partial "sidebar/tree" (dict "context" . "page" $page "level" (add $level 1)) -}} -
  • - {{- end -}} - {{- else -}} -
    - -
    - {{- end -}} - {{- end }} -{{- end -}} diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index 0f406d5..d1a1191 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -10,84 +10,73 @@ -{{- define "sidebar-main" -}} - {{ template "sidebar-tree" (dict "context" .context "level" 0 "page" .page "pageURL" .pageURL "toc" (.toc | default false)) }} +{{- define "partials/sidebar/render-tree" -}} + {{- $context := .context -}} + {{- $page := .page -}} + {{- $pageLink := .page.RelPermalink -}} + {{- range .tree -}} + {{- $active := eq $pageLink .link -}} + {{- $shouldOpen := or (.open) (hasPrefix $pageLink .link) $active | default true }} +
  • + {{- partial "sidebar/link" (dict "context" . "active" $active "title" .title "link" .link) -}} + {{- if .section -}} + {{- partial "sidebar/render-tree-branch" (dict "context" $context "entry" .section "page" $page) -}} + {{- end -}} +
  • + {{ end }} {{- end -}} -{{- define "sidebar-tree" -}} - {{- if ge .level 4 -}} - {{- return -}} - {{- end -}} - +{{- define "partials/sidebar/render-tree-branch" -}} {{- $context := .context -}} - {{- $page := .page }} - {{- $pageURL := .page.RelPermalink -}} - {{- $level := .level -}} - {{- $toc := .toc | default false -}} + {{- $page := .page -}} + {{- $entry := .entry -}} + {{- $pageLink := .page.RelPermalink -}} - {{- with $items := union .context.RegularPages .context.Sections -}} - {{- if eq $level 0 -}} - {{- range $items.ByWeight }} - {{- $active := eq $pageURL .RelPermalink -}} - {{- $shouldOpen := or (.Params.sidebar.open) (.IsAncestor $page) $active | default true }} -
  • - {{- template "sidebar-item-link" dict "context" . "active" $active "title" .LinkTitle "link" .RelPermalink -}} - {{- if and $toc $active -}} - {{- partial "sidebar/toc" . -}} +
    + +
    {{- end -}} -{{- define "sidebar-item-link" -}} +{{- define "partials/sidebar/mobile-search" -}} +
    + {{- partialCached "search.html" . -}} +
    +{{- end -}} + +{{- define "partials/sidebar/link" -}} {{- $external := strings.HasPrefix .link "http" -}} - {{- $open := .open | default true -}} {{- end -}} diff --git a/layouts/partials/sidebar/footer.html b/layouts/partials/sidebar/extra.html similarity index 100% rename from layouts/partials/sidebar/footer.html rename to layouts/partials/sidebar/extra.html diff --git a/layouts/partials/sidebar/section-tree.html b/layouts/partials/sidebar/section-tree.html new file mode 100644 index 0000000..efc7fa1 --- /dev/null +++ b/layouts/partials/sidebar/section-tree.html @@ -0,0 +1,32 @@ +{{ $context := . -}} + +{{- $pages := union .RegularPages .Sections -}} +{{- $pages = where $pages "Params.sidebar.exclude" "!=" true -}} + +{{- $data := slice -}} + +{{- range $pages.ByWeight -}} + {{ $structure := (partial "sidebar/section-walk" .) | unmarshal -}} + {{ $data = $data | append $structure -}} +{{ end -}} + +{{- define "partials/sidebar/section-walk" -}} + {{- with . -}} + { + "title": "{{ .LinkTitle | default .File.BaseFileName }}", + "link": "{{ .RelPermalink }}", + "open": {{ .Params.sidebar.open | default false }} + {{- if .IsSection }}, + "section": [ + {{ $pages := union .RegularPages .Sections -}} + {{ $pages = where $pages "Params.sidebar.exclude" "!=" true -}} + {{ range $index, $page := $pages.ByWeight -}} + {{ partial "sidebar/section-walk" . }}{{ if not (ge $index (sub (len $pages) 1)) }},{{ end -}} + {{ end -}} + ] + {{ end -}} + } + {{- end }} +{{- end -}} + +{{ return ($data | jsonify) }}