我想使用架構(gòu)輸出我的面包屑,但是@id重復(fù)兩次URL或有時(shí)重復(fù)更多?因此,如果我訪問該about頁面,則會(huì)看到:"@id":"http://localhost:1313/about/http://localhost:1313/about/",當(dāng)我使用分頁時(shí),它會(huì)重復(fù)更多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貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊
所以我不確定您的列表頁面模板是什么樣的,但是例如在我的
{{ partial "header.html" . }}
應(yīng)該什么時(shí)候
{{ partial "header" . }}
這刪除了重復(fù)的URL。我在標(biāo)題部分中都渲染了所有相同的代碼。

神不在的星期二
TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊
網(wǎng)址重復(fù)的原因有兩個(gè)
雨果熱重裝的已知錯(cuò)誤。但是最終的生產(chǎn)版本將沒有它。因此,運(yùn)行
hugo
并檢查公用文件夾。如果公共文件夾上的問題仍然存在,請(qǐng)檢查您正在執(zhí)行多少次局部操作
{{ $.Scratch.Add "path" .Site.BaseURL }}
。添加一次后,便可以從頭開始在同一頁面的所有部分上獲得相同的數(shù)據(jù)。
我有關(guān)于雨果的面包屑部分的博客帖子,帶有json-ld
我重復(fù)使用相同的草稿在頁面上顯示面包屑。
只需添加搜索引擎的面包屑即可。還向用戶顯示它們。
- 2 回答
- 0 關(guān)注
- 319 瀏覽
添加回答
舉報(bào)
0/150
提交
取消