【问题标题】:Some hyperlinks in Hugo are not correctly renderedHugo 中的某些超链接未正确呈现
【发布时间】:2021-03-04 01:25:51
【问题描述】:

我为 Hugo 写了一个简码:

# bottomlinks.html
<table>
<tr>
<td>
{{ with .Get "link-http" }}
<a href="{{ . }}">Link http</a>
{{ end }}
</td>
<td>
{{ with .Get "link-ftp" }}
<a href="{{ . }}">Link ftp</a>
{{ end }}
</td>
</tr>
</table>

然后在我的“page.md”中添加了以下代码

{{< bottomlinks link-http="https://test.com" link-ftp="ftp://test.com" >}}

然后我启动了 Hugo 0.65.3。

短代码已正确编译到我的网站中,但是,虽然 http 链接被正确识别,但 ftp 链接在 html 代码中被奇怪地翻译,类似于“#ZhjkfdyuZ”

如果我改用字符串

{{<bottomlinks link-http="https://test.com" link-ftp="http://test.com">}}

两个链接都被正确识别。

Hugo 似乎拒绝复制 ftp 链接。

我该如何解决这个问题?

【问题讨论】:

    标签: hyperlink hugo hugo-shortcode


    【解决方案1】:

    您需要通过在标记中添加“| safeURL”来告诉 Hugo 该链接是安全的。 请参阅下面的简码和相应的文档:https://gohugo.io/functions/safeurl/

       # bottomlinks.html
       <table>
           <tr>
               <td>
                   {{ with .Get "link-http" }}
                   <a href="{{ . }}">Link http</a>
                   {{ end }}
               </td>
               <td>
                   {{ with .Get "link-ftp" }}
                   {{ . }}
                   <a href="{{ . | safeURL }}">Link ftp</a>
                   {{ end }}
               </td>
           </tr>
       </table>
    

    【讨论】:

      猜你喜欢
      • 2020-10-09
      • 2019-01-21
      • 2023-04-09
      • 2014-01-31
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      相关资源
      最近更新 更多