我想使用架構輸出我的面包屑,但是@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>
2 回答
一只甜甜圈
TA貢獻1836條經驗 獲得超5個贊
所以我不確定您的列表頁面模板是什么樣的,但是例如在我的
{{ partial "header.html" . }}應該什么時候
{{ partial "header" . }}這刪除了重復的URL。我在標題部分中都渲染了所有相同的代碼。
神不在的星期二
TA貢獻1963條經驗 獲得超6個贊
網址重復的原因有兩個
雨果熱重裝的已知錯誤。但是最終的生產版本將沒有它。因此,運行
hugo并檢查公用文件夾。如果公共文件夾上的問題仍然存在,請檢查您正在執行多少次局部操作
{{ $.Scratch.Add "path" .Site.BaseURL }}。添加一次后,便可以從頭開始在同一頁面的所有部分上獲得相同的數據。
我有關于雨果的面包屑部分的博客帖子,帶有json-ld
我重復使用相同的草稿在頁面上顯示面包屑。
只需添加搜索引擎的面包屑即可。還向用戶顯示它們。
- 2 回答
- 0 關注
- 371 瀏覽
添加回答
舉報
0/150
提交
取消
