mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 15:57:57 +00:00
80 lines
No EOL
2.8 KiB
HTML
80 lines
No EOL
2.8 KiB
HTML
{{- $page := .page }}
|
|
{{- if and (not $page) .context }}
|
|
{{- $page = .context }}
|
|
{{- 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 }}
|
|
{{- end }}
|
|
{{- $url := .url }}
|
|
{{- if strings.HasPrefix $url "HAHAHUGOSHORTCODE" }}
|
|
{{- warnf "%q: WARNING you must call the ref / relref shortcode with '%% %%' instead of '< >' to work correctly for the anchor target attribute" $page.File.Filename }}
|
|
{{- end }}
|
|
{{- $attributes := dict }}
|
|
{{- $title := .title | default "" }}
|
|
{{- $title = trim $title " " }}
|
|
{{- $attributes = $attributes | merge (dict "title" $title) }}
|
|
{{- $content := .content }}
|
|
{{- $target := .target | default "" }}
|
|
{{- $u := urls.Parse $url }}
|
|
{{- $href := $u.String }}
|
|
{{- $path := $u.Path }}
|
|
{{- $linkPage := "" }}
|
|
{{- if $u.IsAbs }}
|
|
{{- $target = "_blank" }}
|
|
{{- if isset $page.Site.Params "externallinktarget" }}
|
|
{{- $target = $page.Site.Params.externalLinkTarget }}
|
|
{{- end }}
|
|
{{- $attributes = $attributes | merge (dict "target" $target) }}
|
|
{{- else }}
|
|
{{- if $path }}
|
|
{{- 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 "/" }}
|
|
{{- range $page.Sites }}
|
|
{{- $lang := .Language.Lang }}
|
|
{{- $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 }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- else }}
|
|
{{- $linkPage = $page.Page }}
|
|
{{- 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 . }}
|
|
{{- end }}
|
|
{{- else }}
|
|
{{- if eq $page.Site.Params.link.errorlevel "warning" }}
|
|
{{- warnf "%q: link '%s' is not a page but linked anyways" $page.File.Filename $url }}
|
|
{{- else if eq $page.Site.Params.link.errorlevel "error" }}
|
|
{{- errorf "%q: link '%s' is not a page" $page.File.Filename $url }}
|
|
{{- end }}
|
|
{{- 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> |