Unique id and managing many internal links

hi
the worse part of Hugo, with huge sites (thousands of interconnected files) is the linking.
i am creating manually an “id” in the frontmatter.
could it be possible to modify the ref so to accept the id {{< ref id=“my-id” >}} and automatically inject the correct path?

another solution would be to use Obsidian ( https://obsidian.md/ which is an amazing editor for linked markdown files) but uses the [[ ]] for links, and Hugo doesn’t support them natively

i’ve been playing with Hocus CSM but doesn’t manage links

what do you suggest?

Hi,

you could write a shortcode. But I don’t how performant this shortcode is for thousands of pages with unique ids. Maybe there are other ideas.

Shortcode

{{ $id := .Get 0 }}
{{ $linkText := .Get 1 }}
{{ range .Site.Pages.ByParam "id" }}
  {{ if eq (.Param "id") $id }}
    <a href="{{ .URL }}">{{ $linkText }}</a>
  {{ end }}
{{ end }}

Usage

{{< ref-id 3000 "link text" >}}
1 Like

this is huge!

works very well… just update .URL to .Permalink:

{{ $id := .Get 0 }}
{{ $linkText := .Get 1 }}
{{ range .Site.Pages.ByParam "id" }}
  {{ if eq (.Param "id") $id }}
    <a href="{{ .Permalink }}">{{ $linkText }}</a>
  {{ end }}
{{ end }}

PS: works well also for bidirectional links

Glad to hear!

Just out of interest: Did you notice a notable difference in building speed?

no, a just made a few links to test

Ok, thank you.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.