diff options
| author | Nikita Shubin <nikita.shubin@maquefel.me> | 2026-05-17 12:02:16 +0300 |
|---|---|---|
| committer | Nikita Shubin <nikita.shubin@maquefel.me> | 2026-05-17 13:01:10 +0300 |
| commit | 0c405e87f37623323125d43ee61237e931ada441 (patch) | |
| tree | db703aa0238d884b0648d4b10df2af75c6d0add5 | |
| parent | c9acbc552b5e346c1e7204b39a281c30aa1f32ac (diff) | |
| download | landau-suite-0c405e87f37623323125d43ee61237e931ada441.tar.gz landau-suite-0c405e87f37623323125d43ee61237e931ada441.zip | |
template: add custom render-link template to handle .md references
Convert markdown links ending with .md to proper page permalinks.
If the target page is not found, warn and fallback to /base-name/.
This is required for leaving relative markdown links as is in content
repo and transform them only during hugo build.
Signed-off-by: Nikita Shubin <nikita.shubin@maquefel.me>
| -rw-r--r-- | template/layouts/_default/_markup/render-link.html | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/template/layouts/_default/_markup/render-link.html b/template/layouts/_default/_markup/render-link.html new file mode 100644 index 0000000..a3bc8bf --- /dev/null +++ b/template/layouts/_default/_markup/render-link.html @@ -0,0 +1,22 @@ +{{- $dest := .Destination -}} +{{- if strings.HasSuffix $dest ".md" -}} + {{- $clean := $dest | strings.TrimPrefix "./" | strings.TrimPrefix "../" | strings.TrimPrefix "/" -}} + {{- $base := strings.TrimSuffix ".md" $clean -}} + + {{- $target := site.GetPage $base -}} + {{- if not $target -}} + {{- $target = site.GetPage (printf "%s.md" $base) -}} + {{- end -}} + + {{- if $target -}} + {{- $dest = $target.RelPermalink -}} + {{- else -}} + {{- $fallback := printf "/%s/" $base -}} + {{- warnf "Markdown link not found: %s → %s" $dest $fallback -}} + {{- $dest = $fallback -}} + {{- end -}} +{{- end -}} + +<a href="{{ $dest | safeURL }}" {{ with .Title }}title="{{ . }}"{{ end }}> + {{- .Text | safeHTML -}} +</a> |
