Skip to content

Commit 82cf952

Browse files
Fix breadcrumb structured data (missing itemListElement)
- Remove invalid RDFa BreadcrumbList/ListItem markup from nav menu (was missing required itemListElement, and mismarked site nav as a breadcrumb trail) - Add proper JSON-LD BreadcrumbList in structured_data.html built from each page's actual ancestor chain (Home > Section > Page) with position/name/item on every entry
1 parent 56c8b58 commit 82cf952

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎layouts/_default/baseof.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
<a href="{{ .Site.BaseURL }}" class="no-style {{ with .Site.Params.TitleCutting }}site-name{{ end }}">{{ .Site.Title }}</a>:~#
4949
{{ range $index, $element := split $url "/" }}{{ $.Scratch.Add "path" $element }}{{ if ne $element "" }}<a href='{{ $.Scratch.Get "path" | absURL }}'>{{ . }}</a>/{{ $.Scratch.Add "path" "/" }}{{ end }}{{ end }}</div></header>
5050
<nav class="terminal-menu">
51-
<ul vocab="https://schema.org/" typeof="BreadcrumbList">
51+
<ul>
5252
{{ range .Site.Params.navlinks }}
53-
<li><a href="{{ absURL .url }}" typeof="ListItem">{{ .name }}</a></li>
53+
<li><a href="{{ absURL .url }}">{{ .name }}</a></li>
5454
{{ end }}
5555
<li>
5656
<button type="button" id="theme-toggle" class="theme-toggle" aria-label="Toggle dark mode" title="Toggle dark mode">

‎themes/hugo-theme-console/layouts/_default/baseof.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
<a href="{{ .Site.BaseURL }}" class="no-style {{ with .Site.Params.TitleCutting }}site-name{{ end }}">{{ .Site.Title }}</a>:~#
4949
{{ range $index, $element := split $url "/" }}{{ $.Scratch.Add "path" $element }}{{ if ne $element "" }}<a href='{{ $.Scratch.Get "path" | absURL }}'>{{ . }}</a>/{{ $.Scratch.Add "path" "/" }}{{ end }}{{ end }}</div></header>
5050
<nav class="terminal-menu">
51-
<ul vocab="https://schema.org/" typeof="BreadcrumbList">
51+
<ul>
5252
{{ range .Site.Params.navlinks }}
53-
<li><a href="{{ absURL .url }}" typeof="ListItem">{{ .name }}</a></li>
53+
<li><a href="{{ absURL .url }}">{{ .name }}</a></li>
5454
{{ end }}
5555
</ul>
5656
</nav>

‎themes/hugo-theme-console/layouts/partials/structured_data.html‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,24 @@
2424
{{ $schema | jsonify (dict "indent" " ") | safeJS }}
2525
</script>
2626
{{- end }}
27+
28+
<!-- JSON-LD BreadcrumbList, emitted on every non-home page -->
29+
{{- if not .IsHome }}
30+
{{- $crumbs := slice . }}
31+
{{- $node := . }}
32+
{{- range $node.Ancestors }}
33+
{{- $crumbs = $crumbs | append . }}
34+
{{- end }}
35+
{{- $crumbs = $crumbs | collections.Reverse }}
36+
{{- $items := slice }}
37+
{{- $pos := 1 }}
38+
{{- range $crumbs }}
39+
{{- $name := cond .IsHome $.Site.Title .Title }}
40+
{{- $items = $items | append (dict "@type" "ListItem" "position" $pos "name" $name "item" .Permalink) }}
41+
{{- $pos = add $pos 1 }}
42+
{{- end }}
43+
{{- $breadcrumb := dict "@context" "https://schema.org" "@type" "BreadcrumbList" "itemListElement" $items }}
44+
<script type="application/ld+json">
45+
{{ $breadcrumb | jsonify (dict "indent" " ") | safeJS }}
46+
</script>
47+
{{- end }}

0 commit comments

Comments
 (0)