1
0
mirror of synced 2025-12-21 02:46:50 -05:00

Decouple redirects from language (#24597)

* experimenting with redirects

* cleanup developer.json

* wip

* clean console.log

* progress

* some progress

* progress

* much progress

* debugging tests

* hacky progress

* ditch latest -> number redirects

* minor

* hacky progress

* lots of progress

* some small fixes

* fix rendering tests

* small fixes

* progress

* undo debugging

* better

* routing tests OK

* more cleaning

* unit tests

* undoing lineending edit

* undoing temporary debugging

* don't ever set this.redirects on Page

* cope with archived version redirects

* adding code comments on the major if statements

* address all feedback

* update README about redirects

* delete invalid test

* fix feedback
This commit is contained in:
Peter Bengtsson
2022-02-14 15:19:10 -05:00
committed by GitHub
parent b381520839
commit 07c8fc3c2a
29 changed files with 5169 additions and 14292 deletions

View File

@@ -33,7 +33,7 @@ export function getPathWithoutVersion(href) {
}
// Return the version segment in a path
export function getVersionStringFromPath(href) {
export function getVersionStringFromPath(href, supportedOnly = false) {
href = getPathWithoutLanguage(href)
// Return immediately if this is a link to the homepage
@@ -65,6 +65,16 @@ export function getVersionStringFromPath(href) {
return allVersions[planObject.latestVersion].version
}
// If the caller of this function explicitly wants to know if the
// version part is *not* supported, they get back `undefined`.
// But this function is used in many other places where it potentially
// doesn't care if the version is supported.
// For example, in lib/redirects/permalinks.js it needs to know if the
// URL didn't contain a valid version.
if (supportedOnly) {
return
}
// Otherwise, return the first segment as-is, which may not be a real supported version,
// but additional checks are done on this segment in getVersionedPathWithoutLanguage
return versionFromPath