Files
docker-docs/layouts/_default/_markup/render-link.html
David Karlsson 2eb97d7fe7 fix: use links with leading slash as-is
Links that started with a slash were being prepended the URL hostname
and rendered as absolute links before. This caused our link checker to
miss broken links that contained a leading slash.

This change fixes this issue by rendering links with a leading slash as-is,
without modification.

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
2023-09-29 21:06:55 +02:00

32 lines
918 B
HTML

{{ $url := .Destination }}
{{- if (strings.HasPrefix $url "http") -}}
{{/* external link, add icon */}}
<a
class="link"
href="{{ $url | safeURL }}"
target="_blank"
rel="noopener"
>{{ .Text | safeHTML }}<span
class="select-none ml-1 align-top text-[1em] material-symbols-rounded"
>open_in_new</span
></a
>
{{- else if (strings.HasPrefix $url "/") -}}
{{/* absolute link, use url as-is */}}
<a class="link" href="{{ $url }}">{{ .Text | safeHTML }}</a>
{{- else -}}
{{/* check if the file links to index.md */}}
{{- if (strings.FindRE `([^_]|^)index.md` $url 1) -}}
<a
class="link"
href="{{ ref .Page (strings.Replace $url "index.md" "_index.md") }}"
>{{ .Text | safeHTML }}</a
>
{{- else -}}
{{/* relative link, use ref */}}
<a class="link" href="{{ ref .Page $url }}"
>{{ .Text | safeHTML }}</a
>
{{- end -}}
{{- end -}}