From b987a46985c81a8b937104bf2b93ba6094144fc9 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 14:41:47 -0500 Subject: [PATCH 01/13] feat: add redirect script --- _static/js/redirect.js | 9 +++++++++ conf.py | 1 + 2 files changed, 10 insertions(+) create mode 100644 _static/js/redirect.js diff --git a/_static/js/redirect.js b/_static/js/redirect.js new file mode 100644 index 00000000..07242679 --- /dev/null +++ b/_static/js/redirect.js @@ -0,0 +1,9 @@ +document.addEventListener('DOMContentLoaded', function () { + // Assuming `window.location.pathname` gives the current relative URL path. + // Replace 'https://new-location.example.com' with your target base URL. + var currentPath = window.location.pathname; + var newBaseURL = 'https://docs.dash.org/en/develop/docs/core/'; + var newURL = newBaseURL + currentPath; + + window.location.replace(newURL); +}); diff --git a/conf.py b/conf.py index 1a7dc6b6..b122fbc8 100644 --- a/conf.py +++ b/conf.py @@ -159,3 +159,4 @@ def setup(app): app.add_js_file('js/pydata-search-close.js') + app.add_js_file('js/redirect.js') \ No newline at end of file From 628dabc675cab48bee8ad83bbefde5b0b2e25a18 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 14:42:39 -0500 Subject: [PATCH 02/13] chore: disable pdf build --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 58491608..d2a3ac21 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -14,4 +14,4 @@ python: install: - requirements: requirements.txt -formats: [ pdf ] +# formats: [ pdf ] From c8035d26c6b3d21c8a320a0160b42af7ca61cc60 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 14:55:21 -0500 Subject: [PATCH 03/13] chore: test update script --- _static/js/redirect.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index 07242679..2d659412 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -1,9 +1,25 @@ +// document.addEventListener('DOMContentLoaded', function () { +// // Assuming `window.location.pathname` gives the current relative URL path. +// // Replace 'https://new-location.example.com' with your target base URL. +// var currentPath = window.location.pathname; +// var newBaseURL = 'https://docs.dash.org/en/develop/docs/core/'; +// var newURL = newBaseURL + currentPath; + +// window.location.replace(newURL); +// }); + document.addEventListener('DOMContentLoaded', function () { - // Assuming `window.location.pathname` gives the current relative URL path. - // Replace 'https://new-location.example.com' with your target base URL. - var currentPath = window.location.pathname; - var newBaseURL = 'https://docs.dash.org/en/develop/docs/core/'; - var newURL = newBaseURL + currentPath; + // Get the current path and host + var currentPath = window.location.pathname; // e.g., /projects/core/en/core-docs-redirects/ + var newBaseURL = 'https://docs.dash.org'; + + // Transform the path + // Remove '/projects/core/' and replace 'en' with 'develop/docs/core' + var transformedPath = currentPath.replace('/projects/core/en/', '/en/develop/docs/core/'); + + // Construct the new URL + var newURL = newBaseURL + transformedPath; + // Redirect to the new URL window.location.replace(newURL); -}); +}); \ No newline at end of file From 45ffc9547520dd6a7d88438963527f6a0bf74e55 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 15:18:09 -0500 Subject: [PATCH 04/13] chore: update script --- _static/js/redirect.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index 2d659412..ca6646e5 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -15,10 +15,15 @@ document.addEventListener('DOMContentLoaded', function () { // Transform the path // Remove '/projects/core/' and replace 'en' with 'develop/docs/core' - var transformedPath = currentPath.replace('/projects/core/en/', '/en/develop/docs/core/'); + // Transform the path by replacing only the start of the path + var transformedPath = currentPath.replace(/^\/projects\/core\/en\/core-docs-redirects\//, '/en/develop/docs/core/'); + var transformedPath = currentPath.replace(/^\/projects\/core\/en\/develop\//, '/en/develop/docs/core/'); + var transformedPath = currentPath.replace(/^\/projects\/core\/en\/latest\//, '/en/latest/docs/core/'); + console.log(transformedPath); // Construct the new URL var newURL = newBaseURL + transformedPath; + console.log(newURL); // Redirect to the new URL window.location.replace(newURL); From b655479cf4de3c3023d5d8cb937f452ea5b92197 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 15:32:15 -0500 Subject: [PATCH 05/13] chore: trigger debugger --- _static/js/redirect.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index ca6646e5..9830ee51 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -13,6 +13,9 @@ document.addEventListener('DOMContentLoaded', function () { var currentPath = window.location.pathname; // e.g., /projects/core/en/core-docs-redirects/ var newBaseURL = 'https://docs.dash.org'; + // Insert a breakpoint + debugger; + // Transform the path // Remove '/projects/core/' and replace 'en' with 'develop/docs/core' // Transform the path by replacing only the start of the path From 1fa2186ec681c6cbc2e01f842ef85cc9b3a7e0e2 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 15:41:53 -0500 Subject: [PATCH 06/13] chore: update script --- _static/js/redirect.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index 9830ee51..6f68265a 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -19,9 +19,20 @@ document.addEventListener('DOMContentLoaded', function () { // Transform the path // Remove '/projects/core/' and replace 'en' with 'develop/docs/core' // Transform the path by replacing only the start of the path - var transformedPath = currentPath.replace(/^\/projects\/core\/en\/core-docs-redirects\//, '/en/develop/docs/core/'); - var transformedPath = currentPath.replace(/^\/projects\/core\/en\/develop\//, '/en/develop/docs/core/'); - var transformedPath = currentPath.replace(/^\/projects\/core\/en\/latest\//, '/en/latest/docs/core/'); + var replacements = [ + { pattern: /^\/projects\/core\/en\/core-docs-redirects\//, replacement: '/en/develop/docs/core/' }, + { pattern: /^\/projects\/core\/en\/develop\//, replacement: '/en/develop/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 + } + } console.log(transformedPath); // Construct the new URL From e652cdec640e55970576f5cae3dac44b9d7d733d Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 15:57:03 -0500 Subject: [PATCH 07/13] chore: script update --- _static/js/redirect.js | 1 + 1 file changed, 1 insertion(+) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index 6f68265a..91706115 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -20,6 +20,7 @@ document.addEventListener('DOMContentLoaded', function () { // Remove '/projects/core/' and replace 'en' with 'develop/docs/core' // Transform the path by replacing only the start of the path var replacements = [ + { pattern: /^\/projects\/core\/en\/core-docs-redirects\/docs\//, replacement: '/en/develop/docs/core/' }, { pattern: /^\/projects\/core\/en\/core-docs-redirects\//, replacement: '/en/develop/docs/core/' }, { pattern: /^\/projects\/core\/en\/develop\//, replacement: '/en/develop/docs/core/' }, { pattern: /^\/projects\/core\/en\/latest\//, replacement: '/en/latest/docs/core/' } From 6c9dee66fa18b0c3c6dbfc2e3cd5b6469328de05 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 16:02:57 -0500 Subject: [PATCH 08/13] feat: include anchor --- _static/js/redirect.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index 91706115..298c9dbb 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -11,6 +11,7 @@ document.addEventListener('DOMContentLoaded', function () { // Get the current path and host var currentPath = window.location.pathname; // e.g., /projects/core/en/core-docs-redirects/ + var currentHash = window.location.hash; // This captures any anchor (e.g., #section1) var newBaseURL = 'https://docs.dash.org'; // Insert a breakpoint @@ -37,7 +38,7 @@ document.addEventListener('DOMContentLoaded', function () { console.log(transformedPath); // Construct the new URL - var newURL = newBaseURL + transformedPath; + var newURL = newBaseURL + transformedPath + currentHash; console.log(newURL); // Redirect to the new URL From 606dced592ab5f33ad06a8047fb9011742a50474 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 16:14:32 -0500 Subject: [PATCH 09/13] refactor: update script --- _static/js/redirect.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index 298c9dbb..7970d09b 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -1,29 +1,24 @@ -// document.addEventListener('DOMContentLoaded', function () { -// // Assuming `window.location.pathname` gives the current relative URL path. -// // Replace 'https://new-location.example.com' with your target base URL. -// var currentPath = window.location.pathname; -// var newBaseURL = 'https://docs.dash.org/en/develop/docs/core/'; -// var newURL = newBaseURL + currentPath; - -// window.location.replace(newURL); -// }); +// 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/core-docs-redirects/ + 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 + // Insert a breakpoint for debugging if Developer Tools are open debugger; - // Transform the path - // Remove '/projects/core/' and replace 'en' with 'develop/docs/core' // 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\/core-docs-redirects\/docs\//, replacement: '/en/develop/docs/core/' }, { pattern: /^\/projects\/core\/en\/core-docs-redirects\//, replacement: '/en/develop/docs/core/' }, + { 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/' } ]; @@ -36,10 +31,8 @@ document.addEventListener('DOMContentLoaded', function () { } } - console.log(transformedPath); // Construct the new URL var newURL = newBaseURL + transformedPath + currentHash; - console.log(newURL); // Redirect to the new URL window.location.replace(newURL); From cc6991479294cc0b062132cff84331b9db5bf4e6 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 16:16:03 -0500 Subject: [PATCH 10/13] chore: re-enable pdf build --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index d2a3ac21..58491608 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -14,4 +14,4 @@ python: install: - requirements: requirements.txt -# formats: [ pdf ] +formats: [ pdf ] From 84803776a323e226e9228559735320c63d47ce8f Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 16:17:45 -0500 Subject: [PATCH 11/13] chore: add missing eof line --- _static/js/redirect.js | 2 +- conf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index 7970d09b..36fce51b 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -36,4 +36,4 @@ document.addEventListener('DOMContentLoaded', function () { // Redirect to the new URL window.location.replace(newURL); -}); \ No newline at end of file +}); diff --git a/conf.py b/conf.py index b122fbc8..65407e52 100644 --- a/conf.py +++ b/conf.py @@ -159,4 +159,4 @@ def setup(app): app.add_js_file('js/pydata-search-close.js') - app.add_js_file('js/redirect.js') \ No newline at end of file + app.add_js_file('js/redirect.js') From 3e22281114d3ff7762ce93e1202774f9d2e9b1ad Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 16:24:15 -0500 Subject: [PATCH 12/13] chore: remove test branch redirect --- _static/js/redirect.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index 36fce51b..f3027927 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -14,8 +14,6 @@ document.addEventListener('DOMContentLoaded', function () { // 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\/core-docs-redirects\/docs\//, replacement: '/en/develop/docs/core/' }, - { pattern: /^\/projects\/core\/en\/core-docs-redirects\//, replacement: '/en/develop/docs/core/' }, { 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/' }, From a79124168cd7b95379db54f8ef5963822a711089 Mon Sep 17 00:00:00 2001 From: thephez Date: Mon, 11 Nov 2024 16:43:07 -0500 Subject: [PATCH 13/13] fix: only redirect for transformed url --- _static/js/redirect.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/_static/js/redirect.js b/_static/js/redirect.js index f3027927..80cd573b 100644 --- a/_static/js/redirect.js +++ b/_static/js/redirect.js @@ -29,9 +29,9 @@ document.addEventListener('DOMContentLoaded', function () { } } - // Construct the new URL - var newURL = newBaseURL + transformedPath + currentHash; - - // Redirect to the new URL - window.location.replace(newURL); + // Only redirect if the transformed path is different from the original path + if (transformedPath !== currentPath) { + var newURL = newBaseURL + transformedPath + currentHash; + window.location.replace(newURL); + } });