【问题标题】:Hugo data template telephone number gets rendered as a hashHugo 数据模板电话号码被呈现为哈希
【发布时间】:2022-01-04 06:36:00
【问题描述】:

我对 Hugo 和数据模板有一个奇怪的问题。

我在 json 数据模板中有链接内容,我尝试在 a 标记内呈现,如下所示:

数据/foobar.json:

{ [ { link: 'tel:+123123', text: 'a' }, { link: 'mailto:mail@example.com', text: 'b' ] }

部分.html:

{{ range .Site.Data.foobar }}
  <a href="{{ .link }}">{{ .text }}</a>
{{ end }}

产生:

<a href="#ZgatbplZ">a</a>
<a href="mailto:user@example.com">b</a>

由于某种原因,第一个锚目标呈现为随机散列,但第二个正确。这似乎只有当我用tel: 开始链接时才会发生,我不明白为什么?

【问题讨论】:

    标签: hugo


    【解决方案1】:

    可能的语法应该是:{{ .link | safeURL }}

    https://gohugo.io/functions/safehtml/

    https://gohugo.io/functions/safehtmlattr/#readout

    https://gohugo.io/functions/safeurl/

    https://gohugo.io/functions/urlize/#readout

    这是故意的,因为链接没有被清理。
    请参阅 Go 文档以及元素的呈现方式。
    袖手旁观,不在我的车站附近 - 以上之一将为您指明正确的方向。

    检查并告诉我。

    【讨论】:

      猜你喜欢
      • 2014-12-09
      • 2012-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      • 2012-06-03
      • 2014-08-27
      • 1970-01-01
      相关资源
      最近更新 更多