问题描述
我为雨果写了一个简码:
# 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>
{{< 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">}}
两个链接都可以正确识别。
似乎雨果拒绝复制ftp链接。
我该如何解决问题?
解决方法
您需要通过在标记中添加“ | 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>