link: change cross language URL format - take 2 #850

This commit is contained in:
Sören Weber 2025-02-17 23:32:07 +01:00
parent 59414a1b79
commit a9cc5c74d6
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
6 changed files with 58 additions and 39 deletions

View file

@ -522,6 +522,12 @@ disableDefaultRelref = false
# not be servable from the file system.
disableExplicitIndexURLs = false
# Support legacy language links.
# Default: false
# If set to true, you can link to pages in other languages by using
# `/pir/my-page`. This is not recommended, use ``/my-page?lang=pir` instead.
enableLegacyLanguageLinks = false
# How to open external links.
# Default: '_blank'
# For external links you can define how they are opened in your browser. All

View file

@ -1,7 +1,7 @@
+++
categories = ["howto"]
description = "What options are available for links and images"
options = ["disableDefaultRelref", "disableExplicitIndexURLs"]
options = ["disableDefaultRelref", "disableExplicitIndexURLs", "enableLegacyLanguageLinks"]
title = "Linking"
weight = 5
+++

View file

@ -1,7 +1,7 @@
+++
categories = ["howto"]
description = "What options are available for links and images"
options = ["disableDefaultRelref", "disableExplicitIndexURLs"]
options = ["disableDefaultRelref", "disableExplicitIndexURLs", "enableLegacyLanguageLinks"]
title = "Linking"
weight = 5
+++

View file

@ -28,6 +28,6 @@ weight = -12
}
````
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Support for languages that are written right to left (like Arabic) is now complete and extended to the menu, the top navigation bar and print. You can experience this in the [pirate translation](/pir). This feature is not available in Internet Explorer 11.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Support for languages that are written right to left (like Arabic) is now complete and extended to the menu, the top navigation bar and print. You can experience this in the [pirate translation](/?lang=pir). This feature is not available in Internet Explorer 11.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The scrollbars are now colored according to their variant color scheme to better fit into the visuals.

View file

@ -1,4 +1,3 @@
{{- $page := .page }}
{{- $linkObject := "" }}
{{- $u := urls.Parse .url }}
{{- $path := strings.TrimPrefix "./" $u.Path }}
@ -6,43 +5,57 @@
{{- $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 }}
{{- $site := .page.Site }}
{{- $page := .page }}
{{- $transSite := "" }}
{{- $transPage := "" }}
{{- $lang := $u.Query.Get "lang" }}
{{- if and $site.Params.enableLegacyLanguageLinks (not $lang) }}
{{- /* is it a legacy link into another translation? */}}
{{- if strings.HasPrefix $path "/" }}
{{- range $site.Sites }}
{{- $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 "/") }}
{{- $path = $suffix }}
{{- $transSite = . }}
{{- break }}
{{- end }}
{{- end }}
{{- end }}
{{- if not $transSite }}
{{- $lang = $site.Language.Lang }}
{{- $transSite = $site }}
{{- end }}
{{- else if $lang }}
{{- with where $site.Sites "Language.Lang" "eq" $lang }}
{{- with index . 0 }}
{{- $transSite = . }}
{{- end }}
{{- end }}
{{- else }}
{{- $linkObject = $page.Page }}
{{- $lang = $site.Language.Lang }}
{{- $transSite = $site }}
{{- end }}
{{- if $transSite }}
{{- $transPage = $transSite.GetPage $page.Path }}
{{- if $path }}
{{- with or
(and $searchLocal $searchPage $transPage ($transPage.GetPage $path))
(and $searchLocal $searchPage $transPage ($transPage.GetPage (strings.TrimRight "/" $path)))
(and $searchGlobal $searchPage ($transSite.GetPage $path))
(and $searchGlobal $searchPage ($transSite.GetPage (strings.TrimRight "/" $path)))
(and $searchLocal $searchResource $transPage ($transPage.Resources.Get $path))
(and $searchGlobal $searchResource (resources.Get $path))
}}
{{- $linkObject = . }}
{{- end }}
{{- else if $searchPage }}
{{- $linkObject = $transPage }}
{{- end }}
{{- end }}
{{- return $linkObject }}

View file

@ -1 +1 @@
7.3.2+b243bacf3408c44998c6007b215305c9e4cfcb6e
7.3.2+59414a1b792e2ad40d66ac9c49c9dd8dd0becb39