From 5ed690f68b85f2fe8bf99879b307784d2cdfdfec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Thu, 26 Jan 2023 00:08:25 +0100 Subject: [PATCH] nav: fix breadcrumb for huge installations #446 --- layouts/partials/get-page-depth.hugo | 9 +++++++++ layouts/partials/header.html | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 layouts/partials/get-page-depth.hugo diff --git a/layouts/partials/get-page-depth.hugo b/layouts/partials/get-page-depth.hugo new file mode 100644 index 0000000000..488e766e5c --- /dev/null +++ b/layouts/partials/get-page-depth.hugo @@ -0,0 +1,9 @@ +{{- /* https://discourse.gohugo.io/t/how-to-know-the-section-depth/37302/4 */ -}} +{{- $page := .page }} +{{- $depth := .depth | default 0 }} +{{- with $page.Parent }} + {{- $depth = add $depth 1 }} + {{- partial "get-page-depth.hugo" (dict "page" . "depth" $depth) }} +{{- else }} + {{- $depth }} +{{- end }} \ No newline at end of file diff --git a/layouts/partials/header.html b/layouts/partials/header.html index b52e88ca13..0b346e3811 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -144,7 +144,8 @@ {{- $page := .page }} {{- $to := .to }} {{- $breadcrumb = $breadcrumb | append $to }} - {{- range seq (len .to.Site.AllPages) }} + {{- $depth := int (partial "get-page-depth.hugo" (dict "page" $page)) }} + {{- range seq $depth }} {{- $to = $to.Parent }} {{- if $to }} {{- $breadcrumb = $breadcrumb | append $to }}