From ccbfa7a23e45882fada9beebeb44ee14e5e22896 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Fri, 14 Jun 2024 09:17:39 -0400 Subject: [PATCH 1/6] [i18n] Initial multilingual support for redirects with ja example --- content/ja/docs/specs.md | 11 ++++++ layouts/index.redirects | 4 +++ layouts/partials/func/trim-lines.html | 3 ++ layouts/partials/redirects/sites.redirects | 39 ++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 content/ja/docs/specs.md create mode 100644 layouts/partials/func/trim-lines.html create mode 100644 layouts/partials/redirects/sites.redirects diff --git a/content/ja/docs/specs.md b/content/ja/docs/specs.md new file mode 100644 index 000000000000..0bf9f5335bbd --- /dev/null +++ b/content/ja/docs/specs.md @@ -0,0 +1,11 @@ +--- +title: Specifications +linkTitle: Specs ↗ +description: _Redirect page_ +weight: 960 +# _build: { render: link } +redirect: /docs/specs # TODO: this will need to be /en/... +redirects: [{ from: '*', to: ':splat' }] +--- + +Netlify redirect target: [{{% param "title" %}}]({{% param "redirect" %}}). diff --git a/layouts/index.redirects b/layouts/index.redirects index 280f6762074b..7e7f4ac8073a 100644 --- a/layouts/index.redirects +++ b/layouts/index.redirects @@ -72,3 +72,7 @@ {{ end }} {{ return $result }} {{ end }} + +{{/* Multilingual support */ -}} + +{{ partial "redirects/sites.redirects" . | partial "func/trim-lines.html" -}} diff --git a/layouts/partials/func/trim-lines.html b/layouts/partials/func/trim-lines.html new file mode 100644 index 000000000000..db3b92212962 --- /dev/null +++ b/layouts/partials/func/trim-lines.html @@ -0,0 +1,3 @@ +{{ range split . "\n" -}} +{{ trim . " \t" }} +{{ end -}} diff --git a/layouts/partials/redirects/sites.redirects b/layouts/partials/redirects/sites.redirects new file mode 100644 index 000000000000..9240260dfaf7 --- /dev/null +++ b/layouts/partials/redirects/sites.redirects @@ -0,0 +1,39 @@ +{{/* Redirect for default language when .LanguagePrefix is empty. */ -}} + +{{ $defaultLang := "" -}} +{{ with .Site.Sites.Default -}} + {{ if eq .LanguagePrefix "" -}} + {{ with .Language.Lang -}} + {{ $defaultLang = . -}} + /{{ . }} / + /{{ . }}/* /:splat + {{ end -}} + {{ end -}} +{{ end -}} + +{{/* Process non-default languages. */ -}} + +{{ range after 1 .Sites -}} + + {{ $siteLang := .Language.Lang -}} + + # Site localization {{ $siteLang }} + {{ range $p := .Pages -}} + + {{ range $p.Params.redirects -}} + {{ $fallbackPage := partial "i18n/fallback-page.html" $p -}} + {{ if or (eq $siteLang $defaultLang) (not $fallbackPage) -}} + {{ $from := cond (strings.HasPrefix .from "/") + .from + (print $p.RelPermalink .from) -}} + {{ $to := cond (strings.HasPrefix .to "/") + .to + (print $p.RelPermalink .to) -}} + {{ $from | printf "%-35s" }} {{ $to }} + {{ else -}} + {{/* # {{ $p.RelPermalink }} */ -}} + {{ end -}} + {{ end -}} + {{ end -}} + +{{ end -}} From 44d56dde5fcb2056cd6dce1ee4bc7736e0324453 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Fri, 14 Jun 2024 09:20:56 -0400 Subject: [PATCH 2/6] Must respect file org --- content/ja/docs/{specs.md => specs/_index.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename content/ja/docs/{specs.md => specs/_index.md} (100%) diff --git a/content/ja/docs/specs.md b/content/ja/docs/specs/_index.md similarity index 100% rename from content/ja/docs/specs.md rename to content/ja/docs/specs/_index.md From 691f08df895fa13e71aaba90fec942381310c856 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Fri, 14 Jun 2024 09:21:37 -0400 Subject: [PATCH 3/6] Add commit hash --- content/ja/docs/specs/_index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/ja/docs/specs/_index.md b/content/ja/docs/specs/_index.md index 0bf9f5335bbd..b021193b2dec 100644 --- a/content/ja/docs/specs/_index.md +++ b/content/ja/docs/specs/_index.md @@ -6,6 +6,7 @@ weight: 960 # _build: { render: link } redirect: /docs/specs # TODO: this will need to be /en/... redirects: [{ from: '*', to: ':splat' }] +default_lang_commit: 3b44fbfa49ced919daea01123abfaed836d2d0ec --- Netlify redirect target: [{{% param "title" %}}]({{% param "redirect" %}}). From bcb946f975123576a4ee694dcff853d0fbcd8a10 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Fri, 14 Jun 2024 09:29:13 -0400 Subject: [PATCH 4/6] Adjust redirect rules --- content/ja/docs/specs/_index.md | 4 ++-- layouts/partials/redirects/sites.redirects | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/content/ja/docs/specs/_index.md b/content/ja/docs/specs/_index.md index b021193b2dec..122967dea700 100644 --- a/content/ja/docs/specs/_index.md +++ b/content/ja/docs/specs/_index.md @@ -4,8 +4,8 @@ linkTitle: Specs ↗ description: _Redirect page_ weight: 960 # _build: { render: link } -redirect: /docs/specs # TODO: this will need to be /en/... -redirects: [{ from: '*', to: ':splat' }] +redirect: /en/docs/specs +redirects: [{ from: '*', to: '/en/docs/specs/:splat' }] default_lang_commit: 3b44fbfa49ced919daea01123abfaed836d2d0ec --- diff --git a/layouts/partials/redirects/sites.redirects b/layouts/partials/redirects/sites.redirects index 9240260dfaf7..b7b68351a244 100644 --- a/layouts/partials/redirects/sites.redirects +++ b/layouts/partials/redirects/sites.redirects @@ -13,6 +13,8 @@ {{/* Process non-default languages. */ -}} +/ja/docs/specs /en/docs/specs/ + {{ range after 1 .Sites -}} {{ $siteLang := .Language.Lang -}} From 84596624ac3f2ae6e91caac5bd521884ccaac66c Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Fri, 14 Jun 2024 12:04:13 -0400 Subject: [PATCH 5/6] Update .htmltest.yml --- .htmltest.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.htmltest.yml b/.htmltest.yml index 53e80a8d75fb..b68ed6e7d7fb 100644 --- a/.htmltest.yml +++ b/.htmltest.yml @@ -72,3 +72,5 @@ IgnoreURLs: # list of regexs of paths or URLs to be ignored - ^https://wikipedia.org/wiki/(S.M.A.R.T|Hop_) # TODO move into content/en/blog/2023/contributing-to-otel/index.md once https://github.com/open-telemetry/opentelemetry.io/issues/3889 is implemented - ^https://shorturl.at/vLYZ0$ + # TODO remove the following temporary ignore rule (@chalin) + - ^/en/docs/specs$ From 258851b28248f292fe58702917f6f7812af1e3d1 Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Fri, 14 Jun 2024 12:13:45 -0400 Subject: [PATCH 6/6] Force 301 --- content/ja/docs/specs/_index.md | 2 +- layouts/partials/redirects/sites.redirects | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/content/ja/docs/specs/_index.md b/content/ja/docs/specs/_index.md index 122967dea700..63087076a600 100644 --- a/content/ja/docs/specs/_index.md +++ b/content/ja/docs/specs/_index.md @@ -4,7 +4,7 @@ linkTitle: Specs ↗ description: _Redirect page_ weight: 960 # _build: { render: link } -redirect: /en/docs/specs +redirect: /en/docs/specs 301! redirects: [{ from: '*', to: '/en/docs/specs/:splat' }] default_lang_commit: 3b44fbfa49ced919daea01123abfaed836d2d0ec --- diff --git a/layouts/partials/redirects/sites.redirects b/layouts/partials/redirects/sites.redirects index b7b68351a244..70aa516cb9b5 100644 --- a/layouts/partials/redirects/sites.redirects +++ b/layouts/partials/redirects/sites.redirects @@ -13,7 +13,7 @@ {{/* Process non-default languages. */ -}} -/ja/docs/specs /en/docs/specs/ +/ja/docs/specs /en/docs/specs/ 301! {{ range after 1 .Sites -}}