2023-07-27 14:14:55 +00:00
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
2023-10-27 22:36:30 +00:00
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'link' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration/#5180" $page.File.Filename }}
2023-07-27 14:14:55 +00:00
{{- end }}
2022-12-16 17:41:22 +00:00
{{- $url := .url }}
2023-10-10 17:36:59 +00:00
{{- if strings.HasPrefix $url "HAHAHUGOSHORTCODE" }}
2023-10-27 22:36:30 +00:00
{{- warnf "%q: WARNING you must call the ref / relref shortcode with '%% %%' instead of '< >' to work correctly for the anchor target attribute" $page.File.Filename }}
2023-10-10 17:36:59 +00:00
{{- end }}
2022-12-16 17:41:22 +00:00
{{- $title := .title | default "" }}
{{- $title = trim $title " " }}
{{- $content := .content }}
{{- $target := .target | default "" }}
{{- if and (eq (len $target) 0) (or (strings.HasPrefix $url "http://") (strings.HasPrefix $url "https://") ) }}
{{- $target = "_blank" }}
2023-07-27 14:14:55 +00:00
{{- if isset $page.Site.Params "externallinktarget" }}
{{- $target = $page.Site.Params.externalLinkTarget }}
2022-12-23 11:24:04 +00:00
{{- end }}
2023-10-24 20:49:12 +00:00
{{- else }}
{{- $url = urls.Parse $url }}
{{- if and $url.Path (not (strings.HasSuffix $url.Path ".html")) (not (strings.HasSuffix $url.Path ".md")) }}
{{- /* ignore old style links with given extension */}}
{{- $found := false }}
{{- $fragment := "" }}
{{- with $url.Fragment }}
{{- $fragment = printf "#%s" . }}
{{- end }}
2023-10-26 20:47:15 +00:00
{{- $path := printf "%s/" (strings.TrimPrefix "/" (strings.TrimSuffix "/" $url.Path)) }}
{{- with $page.Page.GetPage (strings.TrimSuffix "/" $path | default "/") }}
2023-10-24 20:49:12 +00:00
{{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }}
{{- $found = true }}
{{- else }}
{{- /* is it a link into another translation? */}}
2023-10-27 22:37:39 +00:00
{{- range $page.Sites }}
{{- $lang := .Language.Lang }}
2023-10-26 20:47:15 +00:00
{{- $prefix := printf "%s/" $lang }}
{{- if strings.HasPrefix $path $prefix }}
{{- $path = strings.TrimPrefix $prefix $path | default "/" }}
2023-10-27 22:37:39 +00:00
{{- with .GetPage (strings.TrimSuffix "/" $path | default "/") }}
{{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }}
{{- $found = true }}
2023-10-24 20:49:12 +00:00
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if not $found }}
2023-10-27 22:36:30 +00:00
{{- warnf "%q: no page was found for link '%s'" $page.File.Filename $url.Path }}
2023-10-24 20:49:12 +00:00
{{- end }}
{{- end }}
2023-10-28 20:27:45 +00:00
{{- end -}}
2022-12-23 11:24:04 +00:00
< a href = "{{ $url | safeURL }}" { { if $ title } } title = "{{ $title }}" { { end } } { { if gt ( len $ target ) 0 } } target = "{{ $target }}" { { end } } > {{ $content | safeHTML }}< / a >