Hugo:如何在短代码中创建到页面的链接?



在一个简短的代码中,我想创建一个链接到一个hugo页面,我该怎么做呢?

我试着

{{< ref "page_name" >}}

但是我得到一个错误parse failed unexpected "<" in command

我可以使用例如<a href="https:/www.example.com/test/">Test</a>,但这是绑定到网站托管的域名,我希望能够使用它没有这个限制。

Thanks for the help

也许你需要的是relref

来自文档:

{{< relref "document" >}}
{{< relref "document.md" >}}
{{< relref "#anchor" >}}
{{< relref "/blog/my-post.md" >}}

[]()<- Hugo页面是降价的-这是创建降价链接的方法。

:

[Test](/test/)

如果你想特别使用一个短代码,其他的短代码也可以——但是——上面给了你描述你想要的。

我发现了如何做到这一点,这个链接很有帮助:

https://github.com/parsiya/Hugo-Shortcodes/blob/master/shortcodes/xref.html

所以在短代码中我使用:

{{ $path := .Get "path" }}
{{ $path := trim $path "/" }}
<!-- now pass it to the relref function -->
{{ $relreflink := relref . $path }}
<a href="{{ $relreflink }}" title="Some title" rel="nofollow" target="_blank">Some text</a>

在降价代码中,我可以使用:

{{< my-shortcode path="/my_page" >}}

似乎可行。

最新更新