网址重复。

我想使用架构输出我的面包屑,但是@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>


Qyouu
浏览 267回答 2
2回答

一只甜甜圈

所以我不确定您的列表页面模板是什么样的,但是例如在我的{{&nbsp;partial&nbsp;"header.html"&nbsp;.&nbsp;}}应该什么时候{{&nbsp;partial&nbsp;"header"&nbsp;.&nbsp;}}这删除了重复的URL。我在标题部分中都渲染了所有相同的代码。

神不在的星期二

网址重复的原因有两个雨果热重装的已知错误。但是最终的生产版本将没有它。因此,运行hugo并检查公用文件夹。如果公共文件夹上的问题仍然存在,请检查您正在执行多少次局部操作{{ $.Scratch.Add "path" .Site.BaseURL }}。添加一次后,便可以从头开始在同一页面的所有部分上获得相同的数据。我有关于雨果的面包屑部分的博客帖子,带有json-ld我重复使用相同的草稿在页面上显示面包屑。只需添加搜索引擎的面包屑即可。还向用户显示它们。
打开App,查看更多内容
随时随地看视频慕课网APP