mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
link: make pretty ugly #775
This commit is contained in:
parent
e1cc3bdeab
commit
a92caac1f1
1 changed files with 30 additions and 28 deletions
|
@ -16,41 +16,43 @@
|
||||||
{{- $u := urls.Parse $url }}
|
{{- $u := urls.Parse $url }}
|
||||||
{{- $href := $u.String }}
|
{{- $href := $u.String }}
|
||||||
{{- $path := $u.Path }}
|
{{- $path := $u.Path }}
|
||||||
{{- if strings.HasPrefix $href "#" }}
|
{{- $linkPage := "" }}
|
||||||
{{- $href = printf "%s#%s" $page.Page.RelPermalink $u.Fragment }}
|
{{- if $u.IsAbs }}
|
||||||
{{- else if $u.IsAbs }}
|
|
||||||
{{- $target = "_blank" }}
|
{{- $target = "_blank" }}
|
||||||
{{- if isset $page.Site.Params "externallinktarget" }}
|
{{- if isset $page.Site.Params "externallinktarget" }}
|
||||||
{{- $target = $page.Site.Params.externalLinkTarget }}
|
{{- $target = $page.Site.Params.externalLinkTarget }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $attributes = $attributes | merge (dict "target" $target) }}
|
{{- $attributes = $attributes | merge (dict "target" $target) }}
|
||||||
{{- else if $path }}
|
{{- else }}
|
||||||
{{- $linkPage := "" }}
|
{{- if $path }}
|
||||||
{{- with or
|
{{- with or
|
||||||
($page.Page.GetPage $path)
|
($page.Page.GetPage $path)
|
||||||
($page.Page.Resources.Get $path)
|
($page.Page.Resources.Get $path)
|
||||||
(resources.Get $path)
|
(resources.Get $path)
|
||||||
}}
|
}}
|
||||||
{{- $linkPage = . }}
|
{{- $linkPage = . }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{- /* is it a link into another translation? */}}
|
{{- /* is it a link into another translation? */}}
|
||||||
{{- if strings.HasPrefix $path "/" }}
|
{{- if strings.HasPrefix $path "/" }}
|
||||||
{{- range $page.Sites }}
|
{{- range $page.Sites }}
|
||||||
{{- $lang := .Language.Lang }}
|
{{- $lang := .Language.Lang }}
|
||||||
{{- $prefix := printf "/%s" $lang }}
|
{{- $prefix := printf "/%s" $lang }}
|
||||||
{{- $suffix := strings.TrimPrefix $prefix $path | default "/" }}
|
{{- $suffix := strings.TrimPrefix $prefix $path | default "/" }}
|
||||||
{{- if and (strings.HasPrefix $path $prefix) (strings.HasPrefix $suffix "/") }}
|
{{- if and (strings.HasPrefix $path $prefix) (strings.HasPrefix $suffix "/") }}
|
||||||
{{- with or
|
{{- with or
|
||||||
(.GetPage $suffix)
|
(.GetPage $suffix)
|
||||||
(.Resources.Get $suffix)
|
(.Resources.Get $suffix)
|
||||||
(resources.Get $suffix)
|
(resources.Get $suffix)
|
||||||
}}
|
}}
|
||||||
{{- $linkPage = . }}
|
{{- $linkPage = . }}
|
||||||
{{- break }}
|
{{- break }}
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- $linkPage = $page.Page }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with $linkPage }}
|
{{- with $linkPage }}
|
||||||
{{- $href = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}
|
{{- $href = partial "relLangPrettyUglyURL.hugo" (dict "to" .) }}
|
||||||
|
@ -62,9 +64,9 @@
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
{{- if eq $page.Site.Params.link.errorlevel "warning" }}
|
{{- if eq $page.Site.Params.link.errorlevel "warning" }}
|
||||||
{{- warnf "%q: link '%s' is not a page but linked anyways" $page.File.Filename $u.Path }}
|
{{- warnf "%q: link '%s' is not a page but linked anyways" $page.File.Filename $url }}
|
||||||
{{- else if eq $page.Site.Params.link.errorlevel "error" }}
|
{{- else if eq $page.Site.Params.link.errorlevel "error" }}
|
||||||
{{- errorf "%q: link '%s' is not a page" $page.File.Filename $u.Path }}
|
{{- errorf "%q: link '%s' is not a page" $page.File.Filename $url }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
Loading…
Reference in a new issue