mirror of
https://github.com/docker/docs.git
synced 2026-03-31 16:28:59 +07:00
For some inexplicable reason, the link render hook was failing, probably caused by cases where goldmark was called recursively by shortcodes. This change changas the render hook to use the global `pages` pointer instead of the .Pages pointer of the render hook context. Seems to work. Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
34 lines
1.0 KiB
HTML
34 lines
1.0 KiB
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="pl-1 icon-svg icon-sm">
|
|
{{- partialCached "icon" "open_in_new" "open_in_new" -}}
|
|
</span></a>
|
|
{{- else if (strings.HasPrefix $url "/") -}}
|
|
{{ if (strings.HasSuffix (urls.Parse $url).Path ".md") }}
|
|
{{/* abs path to markdown file, use ref */}}
|
|
{{ $url = (ref page $url) }}
|
|
{{ end }}
|
|
<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 -}}
|