diff --git a/layouts/partials/header/breadcrumbs.html b/layouts/partials/header/breadcrumbs.html index 756de5f76b3df253a15d4a65abae11a9db51a9ec..49ece65c5519b610a8d8514293032b08581cb8a9 100644 --- a/layouts/partials/header/breadcrumbs.html +++ b/layouts/partials/header/breadcrumbs.html @@ -2,59 +2,17 @@ {{- $path := strings.TrimSuffix "/" .RelPermalink -}} {{- $length := len (split $path "/") }} <ol itemscope itemtype="https://schema.org/BreadcrumbList" class="breadcrumb"> - {{- template "breadcrumbOptimized" - (dict - "p1" . - "p2" . - "path" $path - "position" $length - ) -}} + {{ range $index, $item := .Params.breadcrumbs }} + <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="breadcrumb-item{{- if not $item.path }} active{{ end }}"{{- if not $item.path }} aria-current="page"{{ end }}> + {{- if $item.path -}} + <a itemprop="item" href="{{ $item.path }}"> + {{- end -}} + <span itemprop="name">{{- partial "PrepareHTML" $item.title -}}</span> + {{- if $item.path -}} + </a> + {{- end -}} + <meta itemprop="position" content="{{- add $index 1 -}}"> + </li> + {{ end }} </ol> </nav> - -{{- define "breadcrumbOptimized" -}} - {{- $positionNext := sub .position 1 -}} - {{- if .p1.Parent -}} - {{- $path := strings.TrimSuffix "/" .path -}} - {{- $split := path.Split $path -}} - {{/* - {{ .p1.Parent.RelPermalink }} <br> {{ $split.Dir }} <br> - */}} - {{- if eq .p1.Parent.RelPermalink $split.Dir -}} - {{/* Normal case, parent matches permalink<br><br> */}} - {{- 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<br><br> */}} - {{- $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 }} - <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem" class="breadcrumb-item{{- if .active }} active{{ end }}"{{- if .active }} aria-current="page"{{ end }}> - {{- if not .active -}} - <a itemprop="item" href="{{ .page.Permalink }}"> - {{- end -}} - <span itemprop="name">{{- partial "PrepareHTML" $title -}}</span> - {{- if not .active -}} - </a> - {{- end -}} - <meta itemprop="position" content="{{- .position -}}"> - </li> - {{- end -}} -{{- end -}} \ No newline at end of file