Back to Genai Toolbox

Body End

.hugo/layouts/partials/hooks/body-end.html

1.1.01.7 KB
Original Source

{{- $navLinks := slice -}} {{- $targetSections := slice -}} {{- /* Resolve root navigation section */ -}} {{- $docsRoot := site.GetPage "/docs" -}} {{- if $docsRoot -}} {{- $targetSections = $docsRoot.Sections.ByWeight -}} {{- else -}} {{- $targetSections = site.Home.Sections.ByWeight -}} {{- end -}} {{- /* Determine active top-level directory */ -}} {{- if .FirstSection -}} {{- $topLevelFolder := .FirstSection.Section -}} {{- if or (findRE ^v[0-9]+ $topLevelFolder) (eq $topLevelFolder "dev") -}} {{- $targetSections = .FirstSection.Sections.ByWeight -}} {{- end -}} {{- end -}} {{- /* Construct navigation link dataset */ -}} {{- range $targetSections -}} {{- if .Title -}} {{- $manualLink := .Params.manualLink | default "" -}} {{- $icon := .Params.icon | default "" -}} {{- $isRightSide := ne $manualLink "" -}} {{- $navLinks = $navLinks | append (dict "name" .Title "url" .RelPermalink "redirect" $manualLink "icon" $icon "isRight" $isRightSide) -}} {{- end -}} {{- end -}} {{- /* Compile shared tools data for sidebar injection */ -}} {{- $dynamicLinks := dict -}} {{- range .Site.Pages -}} {{- if .Params.shared_tools -}} {{- $targetURL := .RelPermalink -}} {{- $targetData := slice -}} {{- range .Params.shared_tools -}} {{- $sourceSection := site.GetPage .source -}} {{- if $sourceSection -}} {{- $links := slice -}} {{- range $sourceSection.Pages -}} {{- $links = $links | append (dict "title" .Title "url" .RelPermalink) -}} {{- end -}} {{- $targetData = $targetData | append (dict "header" .header "links" $links) -}} {{- end -}} {{- end -}} {{- if gt (len $targetData) 0 -}} {{- $dynamicLinks = merge $dynamicLinks (dict $targetURL $targetData) -}} {{- end -}} {{- end -}} {{- end -}}