2023-07-27 14:14:55 +00:00
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
2023-11-20 23:53:33 +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 }}
2024-02-16 23:49:50 +00:00
{{- $attributes := dict }}
2022-12-16 17:41:22 +00:00
{{- $title := .title | default "" }}
{{- $title = trim $title " " }}
2024-02-16 23:49:50 +00:00
{{- $attributes = $attributes | merge (dict "title" $title) }}
2022-12-16 17:41:22 +00:00
{{- $content := .content }}
{{- $target := .target | default "" }}
2024-02-16 23:49:50 +00:00
{{- $u := urls.Parse $url }}
{{- $href := $u.String }}
{{- $path := $u.Path }}
{{- if $u.IsAbs }}
2022-12-16 17:41:22 +00:00
{{- $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 }}
2024-02-16 23:49:50 +00:00
{{- $attributes = $attributes | merge (dict "target" $target) }}
{{- else if $path }}
{{- $linkPage := "" }}
{{- with or
($page.Page.GetPage $path)
($page.Page.Resources.Get $path)
(resources.Get $path)
}}
{{- $linkPage = . }}
{{- else }}
{{- /* is it a link into another translation? */}}
{{- if strings.HasPrefix $path "/" }}
2023-10-27 22:37:39 +00:00
{{- range $page.Sites }}
{{- $lang := .Language.Lang }}
2024-02-16 23:49:50 +00:00
{{- $prefix := printf "/%s" $lang }}
{{- $suffix := strings.TrimPrefix $prefix $path | default "/" }}
{{- if and (strings.HasPrefix $path $prefix) (strings.HasPrefix $suffix "/") }}
{{- with or
(.GetPage $suffix)
(.Resources.Get $suffix)
(resources.Get $suffix)
}}
{{- $linkPage = . }}
{{- break }}
2023-10-24 20:49:12 +00:00
{{- end }}
{{- end }}
{{- end }}
{{- end }}
2024-02-16 23:49:50 +00:00
{{- end }}
{{- with $linkPage }}
{{- $href = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}
{{- with $u.RawQuery }}
{{- $href = printf "%s?%s" $href . }}
{{- end }}
{{- with $u.Fragment }}
{{- $href = printf "%s#%s" $href . }}
2023-10-24 20:49:12 +00:00
{{- end }}
2024-02-16 23:49:50 +00:00
{{- else }}
{{- warnf "%q: no page was found for link '%s'" $page.File.Filename $u.Path }}
2023-10-24 20:49:12 +00:00
{{- end }}
2024-02-16 23:49:50 +00:00
{{- end }}
{{- $attributes = $attributes | merge (dict "href" $href) -}}
< a
{{- range $k, $v := $attributes }}
{{- if $v }}
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end }}
{{- end -}}
>{{ $content | safeHTML }}< / a >