我想使用架构输出我的面包屑,但是@id重复两次URL或有时重复更多?因此,如果我访问该about页面,则会看到:
"@id":"http://localhost:1313/about/http://localhost:1313/about/",
当我使用分页时,它会重复更多URL:
"@id":"http://localhost:1313/blog/http://localhost:1313/blog//http://localhost:1313/blog/http://localhost:1313/blog//http://localhost:1313/blog/http://localhost:1313/blog/",
我正在使用的代码: 摘自:https : //gohugohq.com/partials/breadcrumb-partial-with-structured-data-in-hugo/
{{ $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }}
{{ $.Scratch.Add "path" .Site.BaseURL }}
{{ $.Scratch.Add "breadcrumb" (slice (dict "url" .Site.BaseURL "name" "home" "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>
一只甜甜圈
神不在的星期二
相关分类