{{- define "breadcrumbOptimized" -}} {{- $positionNext := sub .position 1 -}} {{- if .p1.Parent -}} {{- $path := strings.TrimSuffix "/" .path -}} {{- $split := path.Split $path -}} {{/* {{ .p1.Parent.RelPermalink }}
{{ $split.Dir }}
*/}} {{- if eq .p1.Parent.RelPermalink $split.Dir -}} {{/* Normal case, parent matches permalink

*/}} {{- template "breadcrumbOptimized" (dict "p1" .p1.Parent "p2" .p2 "path" $split.Dir "position" $positionNext) -}} {{- else -}} {{/* Dissonant case, the supposed parent does not have the correct path, so we do an expensive search

*/}} {{- $page := partial "GetPageByUrl" $split.Dir -}} {{- if $page -}} {{- template "breadcrumbOptimized" (dict "p1" $page "p2" .p2 "path" $split.Dir "position" $positionNext) -}} {{- else -}} {{- template "breadcrumbOptimized" (dict "p1" .p1.Parent "p2" .p2 "path" $split.Dir "position" $positionNext) -}} {{- end -}} {{- end -}} {{- else if not .p1.IsNode -}} {{- template "breadcrumbLink" (dict "page" .p1.Site.Home "position" .position) -}} {{- end -}} {{- template "breadcrumbLink" (dict "page" .p1 "active" (eq .p1 .p2) "position" .position) -}} {{- end -}} {{ define "breadcrumbLink" -}} {{/* The pages root is not supposed to show, it's confusing with the home */}} {{- if not (eq .page.RelPermalink "/pages/") -}} {{- $title := .page.Params.breadcrumb_title -}} {{- if not $title -}} {{- $title = .page.Title -}} {{- end -}} {{- $title = chomp $title }} {{- end -}} {{- end -}}