mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-02-13 07:13:29 +00:00
48 lines
No EOL
2.1 KiB
Go Template
48 lines
No EOL
2.1 KiB
Go Template
{{- $page := .page }}
|
|
{{- $linkObject := "" }}
|
|
{{- $u := urls.Parse .url }}
|
|
{{- $path := strings.TrimPrefix "./" $u.Path }}
|
|
{{- $searchLocal := .searchLocal | default true }}
|
|
{{- $searchGlobal := .searchGlobal | default true }}
|
|
{{- $searchPage := .searchPage | default true }}
|
|
{{- $searchResource := .searchResource | default true }}
|
|
{{- if $path }}
|
|
{{- with or
|
|
(and $searchLocal $searchPage ($page.Page.GetPage $path))
|
|
(and $searchLocal $searchPage ($page.Page.GetPage (strings.TrimRight "/" $path)))
|
|
(and $searchGlobal $searchPage (site.GetPage $path))
|
|
(and $searchGlobal $searchPage (site.GetPage (strings.TrimRight "/" $path)))
|
|
(and $searchLocal $searchResource ($page.Page.Resources.Get $path))
|
|
(and $searchGlobal $searchResource (resources.Get $path))
|
|
}}
|
|
{{- $linkObject = . }}
|
|
{{- else }}
|
|
{{- /* is it a link into another translation? */}}
|
|
{{- if strings.HasPrefix $path "/" }}
|
|
{{- range $page.AllTranslations }}
|
|
{{- $lang := .Language.Lang }}
|
|
{{- $prefix := printf "/%s" $lang }}
|
|
{{- $suffix := strings.TrimPrefix $prefix $path | default "/" }}
|
|
{{- /* with the second check we check if the prefix was finished;
|
|
eg. /pir/index.html vs. /pirate/index.html, were the latter is
|
|
an external address outside of this site */}}
|
|
{{- if and (strings.HasPrefix $path $prefix) (strings.HasPrefix $suffix "/") }}
|
|
{{- with or
|
|
(and $searchLocal $searchPage (.GetPage $suffix))
|
|
(and $searchLocal $searchPage (.GetPage (strings.TrimRight "/" $suffix)))
|
|
(and $searchGlobal $searchPage (site.GetPage $path))
|
|
(and $searchGlobal $searchPage (site.GetPage (strings.TrimRight "/" $path)))
|
|
(and $searchLocal $searchResource (.Resources.Get $suffix))
|
|
(and $searchGlobal $searchResource (resources.Get $suffix))
|
|
}}
|
|
{{- $linkObject = . }}
|
|
{{- break }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- else }}
|
|
{{- $linkObject = $page.Page }}
|
|
{{- end }}
|
|
{{- return $linkObject }} |