hyperlink - Hugo 中的某些超链接未正确呈现
问题描述
我为 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 链接。
我该如何解决这个问题?
解决方案
您需要通过在标记中添加“| 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>
推荐阅读
- function - 如何在负载中收集函数返回
- android - Android“存储”和“重用”获取的URI
- javascript - 反应:您可能忘记从定义它的文件中导出组件,或者您可能混淆了默认和命名导入
- elasticsearch - 使用 SSL 调用 ElasticSearch
- rest - 获取 AAD 组的 SubjectDescriptor
- bash - 为什么我的正则表达式匹配子字符串而不是完整字符串?
- scala - 异常检测 Deequ 库中的直方图
- scanf - 在 scanf() 之后使用 Puts() 和 Gets() 不起作用
- ruby - 如何检查用户输入是否包含数字?在红宝石
- ajax - 无法使用 AJAX 和 AWS API Gateway 发布到 AWS Lambda 函数