From 98d0a3dc73e7f66810f54fcaa72f2b9ede8f2341 Mon Sep 17 00:00:00 2001 From: Xin Date: Sun, 22 Oct 2023 11:17:26 +0100 Subject: [PATCH] refactor: split out sidebar elements into partials --- layouts/partials/sidebar.html | 45 +------------------ .../partials/sidebar/collapsible-button.html | 3 ++ layouts/partials/sidebar/footer.html | 10 +++++ layouts/partials/sidebar/toc.html | 19 ++++++++ 4 files changed, 34 insertions(+), 43 deletions(-) create mode 100644 layouts/partials/sidebar/collapsible-button.html create mode 100644 layouts/partials/sidebar/footer.html create mode 100644 layouts/partials/sidebar/toc.html diff --git a/layouts/partials/sidebar.html b/layouts/partials/sidebar.html index cc07748..9a769e0 100644 --- a/layouts/partials/sidebar.html +++ b/layouts/partials/sidebar.html @@ -74,7 +74,7 @@
  • {{- template "sidebar-item-link" dict "context" . "active" $active "title" .LinkTitle "link" .RelPermalink -}} {{- if and $toc $active -}} - {{- template "sidebar-toc" dict "page" . -}} + {{- partial "sidebar/toc" . -}} {{- end -}} {{- template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc -}}
  • @@ -89,7 +89,7 @@
  • {{- template "sidebar-item-link" dict "context" . "active" $active "title" $title "link" .RelPermalink -}} {{- if and $toc $active -}} - {{ template "sidebar-toc" dict "page" . }} + {{ partial "sidebar/toc" . }} {{- end }} {{ template "sidebar-tree" dict "context" . "page" $page "pageURL" $pageURL "level" (add $level 1) "toc" $toc }}
  • @@ -100,41 +100,6 @@ {{- end }} {{- end -}} -{{- define "sidebar-toc" -}} - {{ $page := .page }} - {{ with $page.Fragments.Headings }} - - {{ end }} -{{- end -}} - -{{- define "partials/sidebar/footer" -}} - {{- range site.Menus.sidebar -}} - {{- $name := or (T .Identifier) .Name -}} - {{ if eq .Params.type "separator" }} -
  • - {{ $name }} -
  • - {{ else }} -
  • {{ template "sidebar-item-link" dict "active" false "title" $name "link" (.URL | relLangURL) }}
  • - {{ end }} - {{- end -}} -{{- end -}} - {{- define "sidebar-item-link" -}} {{- $external := strings.HasPrefix .link "http" -}} {{- $open := .open | default true -}} @@ -154,9 +119,3 @@ {{ end -}} {{- end -}} - -{{- define "partials/sidebar/collapsible-button" -}} - - - -{{- end -}} diff --git a/layouts/partials/sidebar/collapsible-button.html b/layouts/partials/sidebar/collapsible-button.html new file mode 100644 index 0000000..a96bd2b --- /dev/null +++ b/layouts/partials/sidebar/collapsible-button.html @@ -0,0 +1,3 @@ + + + diff --git a/layouts/partials/sidebar/footer.html b/layouts/partials/sidebar/footer.html new file mode 100644 index 0000000..37291cb --- /dev/null +++ b/layouts/partials/sidebar/footer.html @@ -0,0 +1,10 @@ +{{- range site.Menus.sidebar -}} + {{- $name := or (T .Identifier) .Name -}} + {{ if eq .Params.type "separator" }} +
  • + {{ $name }} +
  • + {{ else }} +
  • {{ template "sidebar-item-link" dict "active" false "title" $name "link" (.URL | relLangURL) }}
  • + {{ end }} +{{- end -}} diff --git a/layouts/partials/sidebar/toc.html b/layouts/partials/sidebar/toc.html new file mode 100644 index 0000000..1006013 --- /dev/null +++ b/layouts/partials/sidebar/toc.html @@ -0,0 +1,19 @@ +{{ $page := . }} +{{ with $page.Fragments.Headings }} + +{{ end }}