mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-12-04 21:23:07 +00:00
51 lines
No EOL
2.4 KiB
HTML
51 lines
No EOL
2.4 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 }}
|
|
{{- $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" }}
|
|
{{- if isset $page.Site.Params "externallinktarget" }}
|
|
{{- $target = $page.Site.Params.externalLinkTarget }}
|
|
{{- end }}
|
|
{{- 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 }}
|
|
{{- $path := printf "%s/" (strings.TrimPrefix "/" (strings.TrimSuffix "/" $url.Path)) }}
|
|
{{- with $page.Page.GetPage (strings.TrimSuffix "/" $path | default "/") }}
|
|
{{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }}
|
|
{{- $found = true }}
|
|
{{- else }}
|
|
{{- /* is it a link into another translation? */}}
|
|
{{- range $page.Sites }}
|
|
{{- $lang := .Language.Lang }}
|
|
{{- $prefix := printf "%s/" $lang }}
|
|
{{- if strings.HasPrefix $path $prefix }}
|
|
{{- $path = strings.TrimPrefix $prefix $path | default "/" }}
|
|
{{- with .GetPage (strings.TrimSuffix "/" $path | default "/") }}
|
|
{{- $url = printf "%s%s" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) $fragment }}
|
|
{{- $found = true }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- if not $found }}
|
|
{{- warnf "%q: no page was found for link '%s'" $page.File.Filename $url.Path }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end -}}
|
|
<a href="{{ $url | safeURL }}"{{ if $title }} title="{{ $title }}"{{ end }}{{ if gt (len $target) 0 }} target="{{ $target }}"{{ end }}>{{ $content | safeHTML }}</a> |