I am looking for a way to use ref/relref shortcode to auto-generate as a link with the correct Title automatically pulled.
(Test repo: Test repo)
Currently we have to do this manually:
[title]({{< ref "somefile.md" >}})
or in a multilingual site:
[title]({{< ref path="somefile.md" lang="ja" >}})
The more cross-referencing you have, the harder it is to track, and edit (if needed). So, I’m thinking of creating a new shortcode for just this purpose.
However, there is no title params for the ref
function, there are only path
, lang
, and outputFormat
.
I also tried:
{{ with .Site.GetPage "somefile" }}{{ .Title }}{{ end }}
But it only pulls information from the exact same language the viewed page is set to. So if the said page is in “ko”, then .Site.GetPage
will only search ‘ko’ related files.
For example, this does not work:
{{ with .Site.GetPage "/ja/kb/webdev/test-internal.md" }}{{ .Title }}{{ end }}
But without the lang folder, it works but will pull the same language as the current page:
{{ with .Site.GetPage "/kb/webdev/test-internal.md" }}{{ .Title }}{{ end }}
Sample code in .md files
* {{< reftitle path="reftitle-test.md" lang="en-ph" >}}
* {{< reftitle path="reftitle-test.md" lang="ja" >}}
* {{< reftitle path="reftitle-test.md" lang="ko" >}}
I currently have the following in my reftitle.html
shortcode
{{- $lang := .Get "lang" -}}
{{- $path := .Get "path" -}}
{{- $ref := relref . .Params | urlize -}}
<a href="{{ $ref }}">{{ with .Site.GetPage $ref }}{{ .Title }}{{ end }}</a>
- The links are correct since it is using the
ref
. - However, I can not pull the appropriate link title.
- In the example code above, it is empty because it can not find the referenced file because
$ref
value is/ja/kb/webdev/test-internal.md
- In the example code above, it is empty because it can not find the referenced file because
Test repo: Test repo
Or, I’m approaching this incorrectly. ^^;;
Thank you, shalom!