{{- $page := .page }} {{- $linkPage := "" }} {{- $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)) }} {{- $linkPage = . }} {{- 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)) }} {{- $linkPage = . }} {{- break }} {{- end }} {{- end }} {{- end }} {{- end }} {{- end }} {{- else }} {{- $linkPage = $page.Page }} {{- end }} {{- return $linkPage }}