/
breadcrumbs.html
86 lines (77 loc) · 3.09 KB
/
breadcrumbs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{{- if ge (index (split hugo.Version ".") 1 | int) 109 }}
{{- /* Use the new .Ancestors variable available since Hugo v0.109.0 */}}
<nav class="breadcrumbs">
<ol itemscope itemtype="https://schema.org/BreadcrumbList">
{{- range .Ancestors.Reverse }}
{{- /* Do not add "Collections" or "Posts" to the breadcrumb */}}
{{- if not (and
(and .Parent .Parent.IsHome)
(.Section | in (slice "collections" "posts"))
)}}
{{- $titleSupplierPage := . }}
{{- /*
The landing page of a headless section does not necessarily have a
title, and in this case, the headless section's parent page defines
the section's title. To use the '.GetPage' function to get the
parent page instead of the headless section's landing page, just
append a dot to the argument, which works for any file extension.
*/}}
{{- if eq (len .Title) 0 }}
{{- with .File }}
{{- $titleSupplierPage = ((path.Split .Path).Dir
| strings.TrimSuffix "/" | printf "%s."
| $.Site.GetPage) }}
{{- end }}
{{- end }}
{{- partial "breadcrumbs-item.html" $titleSupplierPage }}
<span class="sep" aria-hidden="true">/</span>
{{- end }}
{{- end }}
<li class="current" aria-current="page">{{ .Title }}</li>
</ol>
</nav>
{{- else }}
{{- /* TODO: Remove after fully migrated to Hugo v0.109.0+ */}}
<nav class="breadcrumbs">
<ol itemscope itemtype="https://schema.org/BreadcrumbList">
{{- partial "breadcrumbs-items.html" (dict "p1" . "p2" .) }}
</ol>
</nav>
{{- end }}
{{- define "partials/breadcrumbs-item.html" }}
<li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
<a href="{{ .RelPermalink }}" itemprop="item">
<span itemprop="name">{{ .Title }}</span>
</a>
</li>
{{- end }}
{{- /* TODO: Remove after fully migrated to Hugo v0.109.0+ */}}
{{- define "partials/breadcrumbs-items.html" }}
{{- /*
Recursively generates breadcrumb items. This template is taken from
<https://gohugo.io/content-management/sections/#example-breadcrumb-navigation>.
*/}}
{{- if .p1.Parent }}
{{- partial "breadcrumbs-items.html" (dict "p1" .p1.Parent "p2" .p2) }}
{{- else if not .p1.IsHome }}
{{- partial "breadcrumbs-items.html" (dict "p1" .p1.Site.Home "p2" .p2) }}
{{- end }}
{{- $p1Displayed := .p1 }}
{{- if eq (len .p1.Title) 0 }}
{{- with .p1.File }}
{{- $p1Displayed = ((path.Split .Path).Dir | strings.TrimSuffix "/"
| printf "%s." | $.p1.Site.GetPage) }}
{{- end }}
{{- end }}
{{- if .p1.IsHome }}
{{- partial "breadcrumbs-item.html" $p1Displayed }}
{{- else if not (and .p1.Parent.IsHome
(.p1.Section | in (slice "collections" "posts"))) }}
<span class="sep" aria-hidden="true">/</span>
{{- if eq .p1 .p2 }}
<li class="current" aria-current="page">{{ $p1Displayed.Title }}</li>
{{- else }}
{{- partial "breadcrumbs-item.html" $p1Displayed }}
{{- end }}
{{- end }}
{{- end }}