Skip to content
Snippets Groups Projects
Unverified Commit 96fb4026 authored by Alexis BENOIT's avatar Alexis BENOIT Committed by GitHub
Browse files

Merge pull request #180 from noesya/breadcrumbs

Use data from osuny to create breadcrumbs
parents 592581e8 14a69b4d
No related branches found
No related tags found
No related merge requests found
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment