diff --git a/docs/config/_default/params.toml b/docs/config/_default/params.toml index 9de91b1672..01f7a1c5c6 100644 --- a/docs/config/_default/params.toml +++ b/docs/config/_default/params.toml @@ -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 diff --git a/docs/content/configuration/content/linking/index.en.md b/docs/content/configuration/content/linking/index.en.md index d216ea1e98..9f83dbabda 100644 --- a/docs/content/configuration/content/linking/index.en.md +++ b/docs/content/configuration/content/linking/index.en.md @@ -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 +++ diff --git a/docs/content/configuration/content/linking/index.pir.md b/docs/content/configuration/content/linking/index.pir.md index f33769272f..50b4336bed 100644 --- a/docs/content/configuration/content/linking/index.pir.md +++ b/docs/content/configuration/content/linking/index.pir.md @@ -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 +++ diff --git a/docs/content/introduction/releasenotes/5/12.en.md b/docs/content/introduction/releasenotes/5/12.en.md index b423d0ba18..db188151e7 100644 --- a/docs/content/introduction/releasenotes/5/12.en.md +++ b/docs/content/introduction/releasenotes/5/12.en.md @@ -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. diff --git a/layouts/partials/_relearn/linkObject.gotmpl b/layouts/partials/_relearn/linkObject.gotmpl index c9b2ab15e7..5fba60ef93 100644 --- a/layouts/partials/_relearn/linkObject.gotmpl +++ b/layouts/partials/_relearn/linkObject.gotmpl @@ -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 }} \ No newline at end of file diff --git a/layouts/partials/version.txt b/layouts/partials/version.txt index b58dad1a77..4405f46cf3 100644 --- a/layouts/partials/version.txt +++ b/layouts/partials/version.txt @@ -1 +1 @@ -7.3.2+b243bacf3408c44998c6007b215305c9e4cfcb6e \ No newline at end of file +7.3.2+59414a1b792e2ad40d66ac9c49c9dd8dd0becb39 \ No newline at end of file