Skip to content

Commit

Permalink
feat!: redirect to the new location (dashpay#125)
Browse files Browse the repository at this point in the history
* 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
thephez authored Nov 11, 2024
1 parent 642b8f9 commit e31a341
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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')

0 comments on commit e31a341

Please sign in to comment.