0

我为 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 链接。

我该如何解决这个问题?

4

1 回答 1

0

您需要通过在标记中添加“| 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-11-26T18:46:24.207 回答