From c69fd0059f6ffa159c59e2f405a01a879178c474 Mon Sep 17 00:00:00 2001 From: Simon C Date: Tue, 12 Mar 2024 10:45:48 +0100 Subject: [PATCH] chore: Import layout --- .../partials/sidebar/render-section-menu.html | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 portails/shared/layouts/partials/sidebar/render-section-menu.html diff --git a/portails/shared/layouts/partials/sidebar/render-section-menu.html b/portails/shared/layouts/partials/sidebar/render-section-menu.html new file mode 100644 index 0000000..89b84f9 --- /dev/null +++ b/portails/shared/layouts/partials/sidebar/render-section-menu.html @@ -0,0 +1,102 @@ +{{- /* +Fichier original https://github.com/gethyas/doks-core/blob/main/layouts/partials/sidebar/render-section-menu.html +Based on: https://discourse.gohugo.io/t/automated-nested-menus/42835/2 + +Renders a recursive section menu starting from a page collection or menu. + +As it walks the tree, this partial: + + - Sets class="active" on the active list item + - Sets aria-current="page" on the active anchor + - Sets aria-current="true" on the ancestors of the active anchor + +If you feed it a single page, you must wrap the page in a slice. See examples +below. + +If you feed it a menu, menu entries defined in site configuration must use the +pageRef property, not the URL property. Everything must be a page. + +By default, a home page reference in the page collection or menu will be +skipped. To override this behavior, set $skipHome to false below. + +@param {page} currentPage The page currently being rendered. +@paran {slice} nodes A slice of top level pages or a menu. + +@returns {template.HTML} + +@examples + + {{ with site.Menus.main }} + {{ partial "sidebar/render-section-menu.html" (dict "currentPage" $ "nodes" .) }} + {{ end }} + + {{ with site.Sections }} + {{ partial "sidebar/render-section-menu.html" (dict "currentPage" $ "nodes" .) }} + {{ end }} + + {{ with (.Site.GetPage "section" .Section).Sections }} + {{ partial "sidebar/render-section-menu.html" (dict "currentPage" $ "nodes" .) }} + {{ end }} + + {{ with slice (site.GetPage "/introduction") }} + {{ partial "sidebar/render-section-menu.html" (dict "currentPage" $ "nodes" .) }} + {{ end }} + +*/}} + +{{- /* Configure. */}} +{{- $skipHome := true }} + +{{- /* Get parameters. */}} +{{- $currentPage := .currentPage }} +{{- $nodes := .nodes }} + +{{- /* Render. */}} + + +{{- /* Recurively render list items. */}} +{{- define "walk" }} + {{- $currentPage := .currentPage }} + {{- $node := .node }} + + {{- $linkContent := $node.Page.LinkTitle }} + {{- with $node.Name }} + {{- $linkContent = . }} + {{- end }} + + {{- $ariaCurrent := "" }} + {{- $liClass := "" }} + + {{- if in $currentPage.Ancestors $node.Page }} + {{- $ariaCurrent = "true" }} + {{- end }} + + {{- if $currentPage.Eq $node.Page }} + {{- $ariaCurrent = "page" }} + {{- $liClass = "active" }} + {{- end }} + +
  • + {{- with $node.Page.Pages }} + + {{ $linkContent }} +
      + {{- range . }} + {{- template "walk" (dict "node" . "currentPage" $currentPage) }} + {{- end }} +
    + + {{- else }} + {{ $linkContent }} + {{- end }} +
  • +{{- end }} \ No newline at end of file