Compare commits

...
Sign in to create a new pull request.
Author SHA1 Message Date
Nick Brassel
9fc4e076bd
[docs] Add ability to redirect based on input path. 2024-06-02 16:24:10 +10:00
2 changed files with 17 additions and 2 deletions

View file

@ -2,11 +2,23 @@
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);
if (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);
}

3
docs/_aliases.json Normal file
View file

@ -0,0 +1,3 @@
{
"/feature_audio": "/features/audio"
}