Hi all,
Recently Google Search Console reported problem with one of my page.
I used partial for structured data that was copied from some layout. It looks like this:
{{- $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" -}}
{{- $.Scratch.Add "path" .Site.BaseURL -}}
{{- $.Scratch.Add "breadcrumb" (slice (dict "url" .Site.BaseURL "name" "Main page" "position" 1 )) -}}
{{- range $index, $element := split $url "/" -}}
{{- $.Scratch.Add "path" $element -}}
{{- $.Scratch.Add "path" "/" -}}
{{- if ne $element "" -}}
{{- $.Scratch.Add "breadcrumb" (slice (dict "url" ($.Scratch.Get "path") "name" . "position" (add $index 2))) -}}
{{- end -}}
{{- end -}}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{{ range $.Scratch.Get "breadcrumb" }}{{ if ne .position 1 }},{{ end }}{
"@type": "ListItem",
"position": {{ .position }},
"item": {
"@id": "{{ .url }}",
"name": "{{ .name }}"
}
}{{ end }}]
}
</script>
Everything is ok except situation when I use pagination. When I go to second page (ur: https://mypage.com/page/2/) the generated structured data looks like this:
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "https://mypage.com",
"name": "Main page"
}
}{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "https://mypage.com",
"name": "Main page"
}
}]
}
As you can see this structure is incorrect. The part of this structure was duplicated and comma between this parts is missing. Can you give me some advice how to fix it? I want generate only
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [{
"@type": "ListItem",
"position": 1,
"item": {
"@id": "https://mypage.com",
"name": "Main page"
}
}
for my home page and other where pagination is used.
Thanks in advance for help.