mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-02-13 15:23:30 +00:00
44 lines
No EOL
2.3 KiB
HTML
44 lines
No EOL
2.3 KiB
HTML
{{- /* based on Hugo 0.125.5 render-link.html */}}
|
|
{{- $page := .page }}
|
|
{{- if and (not $page) .context }}
|
|
{{- $page = .context }}
|
|
{{- $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 }}
|
|
{{- end }}
|
|
{{- if strings.HasPrefix .url "HAHAHUGOSHORTCODE" }}
|
|
{{- $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 }}
|
|
{{- end }}
|
|
{{- $attributes := .attributes | default dict }}
|
|
{{- $title := .title | default "" }}
|
|
{{- $title = trim $title " " }}
|
|
{{- $attributes = $attributes | merge (dict "title" ($title | transform.HTMLEscape)) }}
|
|
{{- $content := .content }}
|
|
{{- $target := .target | default "" }}
|
|
{{- $u := urls.Parse .url }}
|
|
{{- $href := $u.String }}
|
|
{{- if $u.IsAbs }}
|
|
{{- partialCached "_relearn/urlExists.gotmpl" (dict "url" .url "page" $page "type" "link") $u.String }}
|
|
{{- $attributes = merge $attributes (dict "rel" "external") }}
|
|
{{- $target = "_blank" }}
|
|
{{- if isset $page.Site.Params "externallinktarget" }}
|
|
{{- $target = $page.Site.Params.externalLinkTarget }}
|
|
{{- end }}
|
|
{{- $attributes = $attributes | merge (dict "target" $target) }}
|
|
{{- else }}
|
|
{{- $linkPage := partial "_relearn/linkPage.gotmpl" (dict "url" $.url "page" $page) }}
|
|
{{- with $linkPage }}
|
|
{{- $href = partial "_relearn/decoratedLink.gotmpl" (dict "url" $.url "page" $page "linkPage" . "param" "link") }}
|
|
{{- else }}
|
|
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
|
|
{{- $msg := printf "%q: link '%s' is not a page or a resource" $filepath .url }}
|
|
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .url "page" $page "param" "link" "msg" $msg) }}
|
|
{{- end }}
|
|
{{- 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> |