Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: redirect to the new location #125

Merged
merged 13 commits into from
Nov 11, 2024
37 changes: 37 additions & 0 deletions _static/js/redirect.js
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);
}
});
1 change: 1 addition & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,4 @@

def setup(app):
app.add_js_file('js/pydata-search-close.js')
app.add_js_file('js/redirect.js')