From 583dd0c97a98e13ee0b683215db37d03589cd59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Mon, 3 Oct 2022 00:07:28 +0200 Subject: [PATCH] theme: revised schema.org breadcrumb navigation #329 to get rid of HTML validation errors and remove descending positions --- layouts/partials/header.html | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 9a673f1207..33e89b9342 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -91,8 +91,7 @@ {{- $showBreadcrumb := (and (not .Params.disableBreadcrumb) (not .Site.Params.disableBreadcrumb)) }} {{- if $showBreadcrumb }} {{- else }} @@ -111,16 +110,31 @@ {{- partial "tags.html" . }} {{- define "breadcrumb" }} - {{- $parent := .page.Parent }} - {{- $ispublished := gt (int (len .page.Permalink)) 0 }} - {{- $depth := .depth }} - {{- if $ispublished }} - {{- $depth = add $depth 1 }} + {{- $breadcrumb := slice }} + {{- $page := .page }} + {{- $breadcrumb = $breadcrumb | append $page }} + {{- range seq (len .page.Site.Home.Pages) }} + {{- $page = $page.Parent }} + {{- if $page }} + {{- $breadcrumb = $breadcrumb | append $page }} + {{- else }} + {{- break }} + {{- end }} {{- end }} - {{- if $parent }} - {{- template "breadcrumb" dict "page" $parent "depth" $depth }} + {{- $len := len $breadcrumb -}} + {{- $breadcrumbReversed := slice }} + {{- range seq $len }} + {{- $breadcrumbReversed = $breadcrumbReversed | append (index $breadcrumb (sub $len .)) }} {{- end }} - {{- if $ispublished }} -
  • {{if .page.Title}}{{ .page.Title }}{{else}}{{ .page.Site.Title }}{{end}}{{ if .depth }} > {{ end }}
  • + {{- $remaining := $len }} + {{- $depth := 0 }} + {{- range $i, $e := $breadcrumbReversed }} + {{- $page := $e }} + {{- $ispublished := gt (int (len $page.Permalink)) 0 }} + {{- $remaining = sub $remaining 1 }} + {{- if $ispublished }} + {{- $depth = add $depth 1 }} +
  • {{ if $remaining }}{{end}}{{ if $page.Title }}{{ $page.Title }}{{ else }}{{ $page.Site.Title }}{{ end }}{{ if $remaining }}{{ end }}
  • {{ if $remaining }} > {{ end }} + {{- end }} {{- end }} {{- end }} \ No newline at end of file