mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
fix: Redirect of old URLs
This commit is contained in:
parent
98c578da02
commit
2d92ffb085
@ -122,8 +122,8 @@
|
|||||||
"typescript": "^5.0.4",
|
"typescript": "^5.0.4",
|
||||||
"unist-util-flatmap": "^1.0.0",
|
"unist-util-flatmap": "^1.0.0",
|
||||||
"unist-util-visit": "^4.1.2",
|
"unist-util-visit": "^4.1.2",
|
||||||
"vitepress": "^1.0.0-alpha.72",
|
"vitepress": "^1.0.0-rc.40",
|
||||||
"vitepress-plugin-search": "^1.0.4-alpha.20"
|
"vitepress-plugin-search": "^1.0.4-alpha.22"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist/",
|
"dist/",
|
||||||
|
@ -8,14 +8,12 @@ import Contributors from '../components/Contributors.vue';
|
|||||||
import HomePage from '../components/HomePage.vue';
|
import HomePage from '../components/HomePage.vue';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import TopBar from '../components/TopBar.vue';
|
import TopBar from '../components/TopBar.vue';
|
||||||
|
|
||||||
import { getRedirect } from './redirect.js';
|
import { getRedirect } from './redirect.js';
|
||||||
|
|
||||||
import { h } from 'vue';
|
import { h } from 'vue';
|
||||||
|
|
||||||
import Theme from 'vitepress/theme';
|
import Theme from 'vitepress/theme';
|
||||||
import '../style/main.css';
|
import '../style/main.css';
|
||||||
import 'uno.css';
|
import 'uno.css';
|
||||||
|
import type { EnhanceAppContext } from 'vitepress';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
...DefaultTheme,
|
...DefaultTheme,
|
||||||
@ -26,19 +24,22 @@ export default {
|
|||||||
'home-features-after': () => h(HomePage),
|
'home-features-after': () => h(HomePage),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
enhanceApp({ app, router }) {
|
enhanceApp({ app, router }: EnhanceAppContext) {
|
||||||
// register global components
|
// register global components
|
||||||
app.component('Mermaid', Mermaid);
|
app.component('Mermaid', Mermaid);
|
||||||
app.component('Contributors', Contributors);
|
app.component('Contributors', Contributors);
|
||||||
router.onBeforeRouteChange = (to) => {
|
router.onBeforeRouteChange = (to) => {
|
||||||
try {
|
try {
|
||||||
const newPath = getRedirect(to);
|
const url = new URL(window.location.origin + to);
|
||||||
|
const newPath = getRedirect(url);
|
||||||
if (newPath) {
|
if (newPath) {
|
||||||
console.log(`Redirecting to ${newPath} from ${window.location}`);
|
console.log(`Redirecting to ${newPath} from ${window.location}`);
|
||||||
// router.go isn't loading the ID properly.
|
// router.go isn't loading the ID properly.
|
||||||
window.location.href = `/${newPath}`;
|
window.location.href = `/${newPath}`;
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -43,5 +43,5 @@ test.each([
|
|||||||
'configure/faq.html#frequently-asked-questions',
|
'configure/faq.html#frequently-asked-questions',
|
||||||
], // with hash
|
], // with hash
|
||||||
])('should process url %s to %s', (link: string, path: string) => {
|
])('should process url %s to %s', (link: string, path: string) => {
|
||||||
expect(getRedirect(link)).toBe(path);
|
expect(getRedirect(new URL(link))).toBe(path);
|
||||||
});
|
});
|
||||||
|
@ -99,8 +99,7 @@ const urlRedirectMap: Record<string, string> = {
|
|||||||
* @param link - The old documentation URL.
|
* @param link - The old documentation URL.
|
||||||
* @returns The new documentation path.
|
* @returns The new documentation path.
|
||||||
*/
|
*/
|
||||||
export const getRedirect = (link: string): string | undefined => {
|
export const getRedirect = (url: URL): string | undefined => {
|
||||||
const url = new URL(link);
|
|
||||||
// Redirects for deprecated vitepress URLs
|
// Redirects for deprecated vitepress URLs
|
||||||
if (url.pathname in urlRedirectMap) {
|
if (url.pathname in urlRedirectMap) {
|
||||||
return `${urlRedirectMap[url.pathname]}${url.hash}`;
|
return `${urlRedirectMap[url.pathname]}${url.hash}`;
|
||||||
|
@ -31,8 +31,8 @@
|
|||||||
"unocss": "^0.58.0",
|
"unocss": "^0.58.0",
|
||||||
"unplugin-vue-components": "^0.26.0",
|
"unplugin-vue-components": "^0.26.0",
|
||||||
"vite": "^4.4.12",
|
"vite": "^4.4.12",
|
||||||
"vite-plugin-pwa": "^0.17.0",
|
"vite-plugin-pwa": "^0.17.5",
|
||||||
"vitepress": "1.0.0-rc.31",
|
"vitepress": "1.0.0-rc.40",
|
||||||
"workbox-window": "^7.0.0"
|
"workbox-window": "^7.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
962
pnpm-lock.yaml
generated
962
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user