forked from dashpay/docs-core
-
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.
feat!: redirect to the new location (dashpay#125)
* feat: add redirect script * chore: disable pdf build * chore: test update script * chore: update script * chore: trigger debugger * chore: update script * chore: script update * feat: include anchor * refactor: update script * chore: re-enable pdf build * chore: add missing eof line * chore: remove test branch redirect * fix: only redirect for transformed url
- Loading branch information
Showing
2 changed files
with
38 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,37 @@ | ||
// As part of the migration of the docs-core repo into dashpay/docs the docs-core pages need to be | ||
// redirect docs.dash.org for anyone still accessing docs via outdated links. This script | ||
// accomplishes the redirects without having to manually define through the readthedocs console. | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
// Get the current path and host | ||
var currentPath = window.location.pathname; // e.g., /projects/core/en/some-branch/ | ||
var currentHash = window.location.hash; // This captures any anchor (e.g., #section1) | ||
var newBaseURL = 'https://docs.dash.org'; | ||
|
||
// Insert a breakpoint for debugging if Developer Tools are open | ||
debugger; | ||
|
||
// Transform the path by replacing only the start of the path | ||
// Remove '/projects/core/' and replace 'en' with 'develop/docs/core' | ||
var replacements = [ | ||
{ pattern: /^\/projects\/core\/en\/develop\/docs\//, replacement: '/en/develop/docs/core/' }, | ||
{ pattern: /^\/projects\/core\/en\/develop\//, replacement: '/en/develop/docs/core/' }, | ||
{ pattern: /^\/projects\/core\/en\/latest\/docs\//, replacement: '/en/latest/docs/core/' }, | ||
{ pattern: /^\/projects\/core\/en\/latest\//, replacement: '/en/latest/docs/core/' } | ||
]; | ||
|
||
var transformedPath = currentPath; // Start with the original path | ||
|
||
for (var i = 0; i < replacements.length; i++) { | ||
if (replacements[i].pattern.test(currentPath)) { | ||
transformedPath = currentPath.replace(replacements[i].pattern, replacements[i].replacement); | ||
break; // Stop after the first match | ||
} | ||
} | ||
|
||
// Only redirect if the transformed path is different from the original path | ||
if (transformedPath !== currentPath) { | ||
var newURL = newBaseURL + transformedPath + currentHash; | ||
window.location.replace(newURL); | ||
} | ||
}); |
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 |
---|---|---|
|
@@ -159,3 +159,4 @@ | |
|
||
def setup(app): | ||
app.add_js_file('js/pydata-search-close.js') | ||
app.add_js_file('js/redirect.js') |