From 282253a7e0c51717234bd64159a37ee527d16dc2 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 3 Jun 2024 08:55:03 +1000 Subject: [docs] Add ability to redirect based on input path. (#23851) --- builddefs/docsgen/.vitepress/theme/QMKLayout.vue | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'builddefs/docsgen/.vitepress') diff --git a/builddefs/docsgen/.vitepress/theme/QMKLayout.vue b/builddefs/docsgen/.vitepress/theme/QMKLayout.vue index 30d0780d7c..9d7a41f9e2 100644 --- a/builddefs/docsgen/.vitepress/theme/QMKLayout.vue +++ b/builddefs/docsgen/.vitepress/theme/QMKLayout.vue @@ -2,11 +2,22 @@ import DefaultTheme from 'vitepress/theme' import { useRouter } from 'vitepress' import { onBeforeMount } from 'vue'; +import aliases from "../../../../docs/_aliases.json"; const router = useRouter() onBeforeMount(async () => { - if (window.location.href.includes('/#/')) { - const newUrl = window.location.href.replace(/\/#\//, '/').replace(/\?id=/, '#'); + // Convert from docsify-style to vitepress-style URLs + let newUrl = window.location.href.replace(/\/#\//, '/').replace(/\?id=/, '#'); + + // Convert any aliases + let testUrl = new URL(newUrl); + while (testUrl.pathname in aliases) { + testUrl.pathname = aliases[testUrl.pathname]; + } + newUrl = testUrl.toString(); + + // Redirect if required + if (newUrl != window.location.href) { window.history.replaceState({}, '', newUrl); await router.go(newUrl); } -- cgit v1.2.3