feat: add BreadcrumbList (enableStructuredBreadcrumbs option)

also fix escape character in url of schema
This commit is contained in:
ZhenShuo Leo
2025-11-21 01:47:43 +08:00
parent c9595934ea
commit 8ab2d8b68a
7 changed files with 32 additions and 4 deletions

View File

@@ -3,11 +3,11 @@
{
"@context": "https://schema.org",
"@type": "WebSite",
"@id": "{{ (site.GetPage "/").Permalink | safeURL }}",
"@id": {{ site.Home.Permalink | safeURL }},
"name": "{{ .Site.Title | safeJS }}",
{{ with .Site.Params.description }}"description": "{{ . | safeJS }}",{{ end }}
{{ with .Site.LanguageCode }}"inLanguage": "{{ . }}",{{ end }}
"url": "{{ (site.GetPage "/").Permalink | safeURL }}",
"url": {{ site.Home.Permalink | safeURL }},
{{ with .Site.Params.keywords }}"keywords": {{ . }},{{ end }}
"publisher" : {
"@type": "Person",
@@ -27,7 +27,7 @@
{{ with .Description }}"description": "{{ . | safeJS }}",{{ end }}
{{ with .Summary }}"abstract": "{{ . | safeJS }}",{{ end }}
{{ with .Site.LanguageCode }}"inLanguage": "{{ . }}",{{ end }}
"url" : "{{ .Permalink }}",
"url" : {{ .Permalink }},
"author" : {
"@type": "Person",
"name": "{{ .Site.Params.Author.name | safeJS }}"
@@ -44,6 +44,28 @@
{{ end }}
"mainEntityOfPage": "true",
"wordCount": "{{ .WordCount }}"
}]
}{{ if site.Params.enableStructuredBreadcrumbs | default false }},
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{{- $breadcrumbs := slice -}}
{{- range .Ancestors -}}
{{- if not .IsHome -}}
{{- $breadcrumbs = $breadcrumbs | append . -}}
{{- end -}}
{{- end -}}
{{- $breadcrumbs = $breadcrumbs | append . -}}
{{- range $index, $element := $breadcrumbs -}}
{
"@type": "ListItem",
"position": {{ add $index 1 }},
"name": "{{ .Title }}",
"item": {{ .Permalink }},
}{{ if ne (add $index 1) (len $breadcrumbs) }},{{ end }}
{{- end -}}
]
}{{ end }}]
</script>
{{ end }}