为了账号安全,请及时绑定邮箱和手机立即绑定

网址重复。

网址重复。

Go
Qyouu 2021-04-16 18:02:16
我想使用架构输出我的面包屑,但是@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。我在标题部分中都渲染了所有相同的代码。


查看完整回答
反对 回复 2021-04-19
?
神不在的星期二

TA贡献1963条经验 获得超6个赞

网址重复的原因有两个

  1. 雨果热重装的已知错误。但是最终的生产版本将没有它。因此,运行hugo并检查公用文件夹。

  2. 如果公共文件夹上的问题仍然存在,请检查您正在执行多少次局部操作{{ $.Scratch.Add "path" .Site.BaseURL }}。添加一次后,便可以从头开始在同一页面的所有部分上获得相同的数据。

我有关于雨果的面包屑部分的博客帖子,带有json-ld

我重复使用相同的草稿在页面上显示面包屑。

只需添加搜索引擎的面包屑即可。还向用户显示它们。


查看完整回答
反对 回复 2021-04-19
  • 2 回答
  • 0 关注
  • 266 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信