Re-write link to perma link
Closed this issue · 1 comments
jixunmoe commented
I was experimenting with custom slug for tags (permalink), and it does not work out-of-the-box.
For both language, it contains the following post meta:
tags = [
"闲聊", # chit chat
"不存在", # non-exist (to test fallback when custom meta file does not exist)
]
As my initial investigation, I've found that you can get the permalink to a tag in this rather verbose way:
<!-- post-info.html, tags rendering -->
{{ range $tag_name := .Params.tags }}
{{ $tag := ($.Site.GetPage (printf "/tags/%s" $tag_name)) }}
<li><a href="{{ $tag.Permalink }}">#{{ $tag.Title | default $tag_name }}</a></li>
{{ end }}
Which manages to render the correct url for both language:
<!-- en -->
<ul class="post-tags">
<li><a href="http://localhost:1313/en/tags/custom-tag/">#Custom title</a></li>
<li><a href="http://localhost:1313/en/tags/%E4%B8%8D%E5%AD%98%E5%9C%A8/">#不存在</a></li>
</ul>
<!-- zh-cn: default -->
<ul class="post-tags">
<li><a href="http://localhost:1313/tags/chitchat/">#闲聊</a></li>
<li><a href="http://localhost:1313/tags/%E4%B8%8D%E5%AD%98%E5%9C%A8/">#不存在</a></li>
</ul>
Is getting late now, so I've just documented the discovery I had. I can do a PR later if required.
PR already created in #133
Reproduce
First config custom permalinks:
# config.toml
[permalinks]
tags = "/tags/:slug/" # set to "/silly-tags/:slug/" also works :D
And define mapping like so:
<!-- file: content/tags/闲聊/_index.md -->
+++
# title is missing for native language, which should fallback to its key "闲聊"
slug = "chitchat"
+++
<!-- file: content/tags/闲聊/_index.en.md -->
+++
title = "Custom title"
slug = "custom-tag" # if this field is missing, it will be derived from title instead of inherit from native language...
+++