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 }}
-
- {{- template "breadcrumb" dict "page" . "depth" 0 }}
+ {{- template "breadcrumb" dict "page" . }}
{{- 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