forked from flutter/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more client-side fragment redirects for old get started pages (fl…
…utter#10357) This adds redirects from the `/get-started/install/<platform>` pages if a fragment (`#link-target-fragment`) from the old page format is specified. These JS based redirects are necessary as fragments aren't sent to the server, so Firebase redirects won't work. We likely won't maintain these indefinitely, but a lot of links referencing these still exist in old versions of tools and the internet, so we can keep them for the foreseeable future. Fixes flutter#10271
- Loading branch information
Showing
6 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const oldToNew = { | ||
'configuring-web-app-support': '/get-started/install/chromeos/web', | ||
|
||
'android-setup-without-android-studio': '/get-started/install/chromeos/android?tab=download#configure-android-development', | ||
'android-setup': '/get-started/install/chromeos/android?tab=download#configure-android-development', | ||
'configuring-android-app-support': '/get-started/install/chromeos/android?tab=download#configure-android-development', | ||
'set-up-your-android-device': '/get-started/install/chromeos/android#configure-your-target-android-device', | ||
'set-up-the-android-emulator': '/get-started/install/chromeos/android#configure-your-target-android-device', | ||
'agree-to-android-licenses': '/get-started/install/chromeos/android#agree-to-android-licenses', | ||
}; | ||
|
||
function handleRedirect() { | ||
const rawOldFragment = window.location.hash; | ||
|
||
// If no fragment was specified, don't do anything. | ||
if (!rawOldFragment) { | ||
return; | ||
} | ||
|
||
const oldFragmentWithHash = rawOldFragment.trim().toLowerCase(); | ||
|
||
// If the fragment is empty, don't do anything. | ||
if (oldFragmentWithHash.length === 0) { | ||
return; | ||
} | ||
|
||
const oldFragment = oldFragmentWithHash.substring(1); | ||
|
||
// If the fragment did not exist, don't do anything. | ||
if (!(oldFragment in oldToNew)) { | ||
return; | ||
} | ||
|
||
const newDestination = oldToNew[oldFragment]; | ||
|
||
// If the desired destination exists, go there. | ||
// Otherwise, don't go anywhere. | ||
fetch(newDestination) | ||
.then((response) => { | ||
if (response.status === 200) { | ||
window.location.replace(newDestination); | ||
} | ||
}).catch((_) => { | ||
}); | ||
} | ||
|
||
const currentLocation = window.location.pathname; | ||
|
||
if (currentLocation.includes('/get-started/install/chromeos') && | ||
currentLocation.split('/') | ||
.filter(value => value.trim().length !== 0).length === 3) { | ||
handleRedirect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const oldToNew = { | ||
'linux-setup': '/get-started/install/linux/desktop', | ||
|
||
'android-setup': '/get-started/install/linux/android#configure-android-development', | ||
'set-up-your-android-device': '/get-started/install/linux/android#configure-your-target-android-device', | ||
'set-up-the-android-emulator': '/get-started/install/linux/android#configure-your-target-android-device', | ||
'agree-to-android-licenses': '/get-started/install/linux/android#agree-to-android-licenses', | ||
|
||
'update-your-path': '/get-started/install/linux/android?tab=download#add-flutter-to-your-path' | ||
}; | ||
|
||
function handleRedirect() { | ||
const rawOldFragment = window.location.hash; | ||
|
||
// If no fragment was specified, don't do anything. | ||
if (!rawOldFragment) { | ||
return; | ||
} | ||
|
||
const oldFragmentWithHash = rawOldFragment.trim().toLowerCase(); | ||
|
||
// If the fragment is empty, don't do anything. | ||
if (oldFragmentWithHash.length === 0) { | ||
return; | ||
} | ||
|
||
const oldFragment = oldFragmentWithHash.substring(1); | ||
|
||
// If the fragment did not exist, don't do anything. | ||
if (!(oldFragment in oldToNew)) { | ||
return; | ||
} | ||
|
||
const newDestination = oldToNew[oldFragment]; | ||
|
||
// If the desired destination exists, go there. | ||
// Otherwise, don't go anywhere. | ||
fetch(newDestination) | ||
.then((response) => { | ||
if (response.status === 200) { | ||
window.location.replace(newDestination); | ||
} | ||
}).catch((_) => { | ||
}); | ||
} | ||
|
||
const currentLocation = window.location.pathname; | ||
|
||
if (currentLocation.includes('/get-started/install/linux') && | ||
currentLocation.split('/') | ||
.filter(value => value.trim().length !== 0).length === 3) { | ||
handleRedirect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters