2024-04-27 14:38:19 +02:00
{{- /* based on Hugo 0.125.5 render-link.html */}}
2023-07-27 16:14:55 +02:00
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
2025-01-31 14:57:10 +01:00
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'link' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $filepath }}
2023-07-27 16:14:55 +02:00
{{- end }}
2024-05-28 21:50:58 +02:00
{{- if strings.HasPrefix .url "HAHAHUGOSHORTCODE" }}
2025-01-31 14:57:10 +01:00
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
{{- warnf "%q: WARNING you must call the ref / relref shortcode with '%% %%' instead of '< >' to work correctly for the anchor target attribute" $filepath }}
2023-10-10 19:36:59 +02:00
{{- end }}
2025-02-05 08:33:02 +01:00
{{- $attributes := .attributes | default dict }}
2022-12-16 18:41:22 +01:00
{{- $title := .title | default "" }}
{{- $title = trim $title " " }}
2024-04-22 22:43:59 +02:00
{{- $attributes = $attributes | merge (dict "title" ($title | transform.HTMLEscape)) }}
2022-12-16 18:41:22 +01:00
{{- $content := .content }}
{{- $target := .target | default "" }}
2025-01-29 20:37:08 +01:00
{{- $u := urls.Parse .url }}
2024-02-17 00:49:50 +01:00
{{- $href := $u.String }}
2024-02-22 19:06:33 +01:00
{{- if $u.IsAbs }}
2025-01-29 18:03:23 +01:00
{{- partialCached "_relearn/urlExists.gotmpl" (dict "url" .url "page" $page "type" "link") $u.String }}
2024-04-07 13:44:48 +02:00
{{- $attributes = merge $attributes (dict "rel" "external") }}
2022-12-16 18:41:22 +01:00
{{- $target = "_blank" }}
2023-07-27 16:14:55 +02:00
{{- if isset $page.Site.Params "externallinktarget" }}
{{- $target = $page.Site.Params.externalLinkTarget }}
2022-12-23 12:24:04 +01:00
{{- end }}
2024-02-17 00:49:50 +01:00
{{- $attributes = $attributes | merge (dict "target" $target) }}
2024-02-22 19:06:33 +01:00
{{- else }}
2025-02-05 23:39:23 +01:00
{{- $linkObject := partial "_relearn/linkObject.gotmpl" (dict "url" $.url "page" $page) }}
{{- with $linkObject }}
{{- $href = partial "_relearn/decoratedLink.gotmpl" (dict "url" $.url "page" $page "linkObject" . "param" "link") }}
2024-02-17 00:49:50 +01:00
{{- else }}
2025-02-05 08:33:02 +01:00
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
2025-01-31 14:57:10 +01:00
{{- $msg := printf "%q: link '%s' is not a page or a resource" $filepath .url }}
2025-01-29 22:17:39 +01:00
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .url "page" $page "param" "link" "msg" $msg) }}
2023-10-24 22:49:12 +02:00
{{- end }}
2024-02-17 00:49:50 +01:00
{{- end }}
{{- $attributes = $attributes | merge (dict "href" $href) -}}
< a
{{- range $k, $v := $attributes }}
{{- if $v }}
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end }}
2025-02-05 08:33:02 +01:00
{{- end }}>{{ $content | safeHTML }}< / a >