diff --git a/layouts/_default/_markup/render-link.html b/layouts/_default/_markup/render-link.html new file mode 100644 index 0000000..6313c92 --- /dev/null +++ b/layouts/_default/_markup/render-link.html @@ -0,0 +1,18 @@ +{{- $link := .Destination -}} +{{- $isRemote := or (strings.HasPrefix $link "http") (strings.HasPrefix $link "mailto") -}} + +{{- if not $isRemote -}} + {{- $url := urls.Parse .Destination -}} + {{- $fragment := "" -}} + {{- with $url.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}} + + {{- /* Try to find the page by its path */ -}} + {{- with .Page.GetPage $url.Path -}} + {{- $link = printf "%s%s" .RelPermalink $fragment -}} + {{- else -}} + {{- /* If the page is not found, throw a warning during build. */ -}} + {{- warnf "Broken link to page: '%s' found in file %s" .Destination .Page.File.Path -}} + {{- end -}} +{{- end -}} + +{{ .Text | safeHTML }}