Skip to content

Commit a5df2f4

Browse files
committed
1 parent 20ce567 commit a5df2f4

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

layouts/partials/templates/schema_json.html

+42-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,46 @@
1616
]
1717
}
1818
</script>
19-
{{- else if .IsPage }}
19+
{{- else if (or .IsPage .IsSection) }}
20+
{{/* BreadcrumbList */}}
21+
{{- $url := replace .Parent.Permalink ( printf "%s" .Site.BaseURL) "" }}
22+
{{- $lang_url := replace $url ( printf "%s" .Lang) "" }}
23+
{{- $bc_list := (split $lang_url "/")}}
24+
25+
{{- $scratch := newScratch }}
26+
<script type="application/ld+json">
27+
{
28+
"@context": "https://schema.org",
29+
"@type": "BreadcrumbList",
30+
"itemListElement": [
31+
{{- range $index, $element := $bc_list }}
32+
33+
{{- $scratch.Add "path" (printf "%s/" $element ) | safeJS }}
34+
{{- $bc_pg := $.Site.GetPage ($scratch.Get "path") -}}
35+
36+
{{- if (and ($bc_pg) (gt (len . ) 0))}}
37+
{{- if (and $index)}}, {{end }}
38+
{
39+
"@type": "ListItem",
40+
"position": {{ add 1 $index }},
41+
"name": {{ $bc_pg.Name }},
42+
"item": {{ $bc_pg.Permalink | safeHTML }}
43+
}
44+
{{- end }}
45+
46+
{{- end }}
47+
{{- /* self-page addition */ -}}
48+
{{- if $bc_list }}, {{end }}
49+
{
50+
"@type": "ListItem",
51+
"position": {{len $bc_list}},
52+
"name": {{ .Name }},
53+
"item": {{ .Permalink | safeHTML }}
54+
}
55+
]
56+
}
57+
</script>
58+
{{- if .IsPage }}
2059
<script type="application/ld+json">
2160
{
2261
"@context": "https://schema.org",
@@ -75,4 +114,6 @@
75114
}
76115
}
77116
</script>
117+
{{ end }}{{/* .IsPage end */}}
118+
78119
{{ end }}

0 commit comments

Comments
 (0)