gpt4 book ai didi

go - 网址重复

转载 作者:数据小太阳 更新时间:2023-10-29 03:11:04 27 4
gpt4 key购买 nike

我想使用模式输出我的面包屑,但是 @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/博客//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>

最佳答案

所以我不确定您的列表页面模板是什么样的,但是例如我的列表页面模板

{{ partial "header.html" . }}

应该是什么时候

{{ partial "header" . }}

这删除了重复的 url。我的 header 部分中有您呈现的所有相同代码。

关于go - 网址重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51628945/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com