* Add schema.org BreadcrumbList to JSON+LD This implementation depends on .Page.Ancestors, which requires Hugo version v0.109.0. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca> * Fix extraneous comma in schema For blog posts we ended up with an extraneous comma due to it being outside the condition for the breadcrumb JSON+LD. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca> * Pretty print breadcrumb JSON+LD for schema Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca> * Make breadcrumbs opt-in on non-blogSections Sections except blogSections (which is a configurable set which is defaulted to sections 'blog' and 'post'), may be part of `breadcrumbSections`. For the breadcrumb Sections, the section and any pages under it will have the `breadcrumb` attribute (of type `BreadcrumbList`) added to the JSON+LD for their schema.org structured data. Update documentation of `params` for example `config.yaml` in README. Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca> --------- Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
29 lines
1,018 B
HTML
29 lines
1,018 B
HTML
{{- $breadcrumbScratch := newScratch -}}
|
|
{{- $crumbScratch := newScratch -}}
|
|
{{- $crumbScratch.Set "itemListElement" (slice) -}}
|
|
{{- $breadPos := 0 -}}
|
|
{{- range .Ancestors.Reverse -}}
|
|
{{- $breadPos = (add $breadPos 1) -}}
|
|
{{- $crumbScratch.Add "itemListElement" (dict
|
|
"@type" "ListItem"
|
|
"position" $breadPos
|
|
"item" (dict
|
|
"@id" .Permalink
|
|
"name" .LinkTitle
|
|
)
|
|
) -}}
|
|
{{- end -}}
|
|
{{- $breadPos = (add $breadPos 1) -}}
|
|
{{- $crumbScratch.Add "itemListElement" (dict
|
|
"@type" "ListItem"
|
|
"position" $breadPos
|
|
"item" (dict
|
|
"@id" .Permalink
|
|
"name" .LinkTitle
|
|
)
|
|
) -}}
|
|
{{- $breadcrumbScratch.SetInMap "breadcrumb" "@context" "https://schema.org" -}}
|
|
{{- $breadcrumbScratch.SetInMap "breadcrumb" "@type" "BreadcrumbList" -}}
|
|
{{- $breadcrumbScratch.SetInMap "breadcrumb" "itemListElement" ($crumbScratch.Get "itemListElement") -}}
|
|
{{- $jsonifiedBreadcrumb := $breadcrumbScratch.Get "breadcrumb" | jsonify (dict "indent" " " "prefix" " ") -}}
|
|
{{- return $jsonifiedBreadcrumb -}}
|