From c64845404492eb86fb156834c8ca008b306f7649 Mon Sep 17 00:00:00 2001 From: Simon Schrottner Date: Tue, 4 Apr 2023 10:11:50 +0200 Subject: [PATCH] docs: improve rendering of links for local markdownfiles Hugo is not really good when it comes to linking markdown files, if they are not within an own folder. With this improvement, we will fetch all relative links, even with `.md` and generate their url different than the [originial version](https://gohugo.io/templates/render-hooks/#link-with-title-markdown-example). Signed-off-by: Simon Schrottner --- docs/layouts/_default/_markup/render-link.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 docs/layouts/_default/_markup/render-link.html diff --git a/docs/layouts/_default/_markup/render-link.html b/docs/layouts/_default/_markup/render-link.html new file mode 100644 index 0000000000..89d0b0d33d --- /dev/null +++ b/docs/layouts/_default/_markup/render-link.html @@ -0,0 +1,13 @@ +{{- if or (strings.HasPrefix .Destination "http") (strings.HasPrefix .Destination "#") -}} +{{ .Text | safeHTML }} +{{- else -}} +{{- $link := . -}} +{{- $internal := urls.Parse .Destination -}} +{{- if $internal.Path -}} +{{- $fragment := "" }} +{{- with $internal.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}} +{{- with .Page.GetPage $internal.Path }}{{ $internal = printf "%s%s" .RelPermalink $fragment }} +{{ $link.Text | safeHTML }} +{{- end -}} +{{- end -}} +{{- end -}}