diff --git a/README.md b/README.md index 8cd211a..d650306 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,13 @@ languageCode: "en-GB" # Set your language code (only needed for none multi params: alpine: # Add AlpineJS, default false. + blogSections: # Sections whose `JSON+LD` in the page `` + - blog # will be `@type: BlogPosting`. + - post # Defaults to a list including only 'post' and 'blog'. + breadcrumbSections: # Sections in which pages will have a `BreadcrumbListing` + - section2 # in the `JSON+LD` in the page's ``. + - section3 # This theme requires Hugo `v0.109.0` or higher to + # generate the `BreadcrumbListing`. cookieConsent: true # Show cookie consent form, default false. contact: "info@example.org" copyright: "This site is licensed under a diff --git a/layouts/partials/meta_breadcrumb_json_ld.html b/layouts/partials/meta_breadcrumb_json_ld.html new file mode 100644 index 0000000..eee976f --- /dev/null +++ b/layouts/partials/meta_breadcrumb_json_ld.html @@ -0,0 +1,29 @@ +{{- $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 -}} diff --git a/layouts/partials/meta_json_ld.html b/layouts/partials/meta_json_ld.html index 6fdafd7..2e3d361 100644 --- a/layouts/partials/meta_json_ld.html +++ b/layouts/partials/meta_json_ld.html @@ -1,8 +1,17 @@