Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Redirect of old URLs #5250

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/mermaid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
"typescript": "^5.0.4",
"unist-util-flatmap": "^1.0.0",
"unist-util-visit": "^4.1.2",
"vitepress": "^1.0.0-alpha.72",
"vitepress-plugin-search": "^1.0.4-alpha.20"
"vitepress": "^1.0.0-rc.40",
"vitepress-plugin-search": "^1.0.4-alpha.22"
},
"files": [
"dist/",
Expand Down
13 changes: 7 additions & 6 deletions packages/mermaid/src/docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import Contributors from '../components/Contributors.vue';
import HomePage from '../components/HomePage.vue';
// @ts-ignore
import TopBar from '../components/TopBar.vue';

import { getRedirect } from './redirect.js';

import { h } from 'vue';

import Theme from 'vitepress/theme';
import '../style/main.css';
import 'uno.css';
import type { EnhanceAppContext } from 'vitepress';

export default {
...DefaultTheme,
Expand All @@ -26,19 +24,22 @@ export default {
'home-features-after': () => h(HomePage),
});
},
enhanceApp({ app, router }) {
enhanceApp({ app, router }: EnhanceAppContext) {
// register global components
app.component('Mermaid', Mermaid);
app.component('Contributors', Contributors);
router.onBeforeRouteChange = (to) => {
try {
const newPath = getRedirect(to);
const url = new URL(window.location.origin + to);
const newPath = getRedirect(url);
if (newPath) {
console.log(`Redirecting to ${newPath} from ${window.location}`);
// router.go isn't loading the ID properly.
window.location.href = `/${newPath}`;
}
} catch (e) {}
} catch (e) {
console.error(e);
}
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ test.each([
'configure/faq.html#frequently-asked-questions',
], // with hash
])('should process url %s to %s', (link: string, path: string) => {
expect(getRedirect(link)).toBe(path);
expect(getRedirect(new URL(link))).toBe(path);
});
3 changes: 1 addition & 2 deletions packages/mermaid/src/docs/.vitepress/theme/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ const urlRedirectMap: Record<string, string> = {
* @param link - The old documentation URL.
* @returns The new documentation path.
*/
export const getRedirect = (link: string): string | undefined => {
const url = new URL(link);
export const getRedirect = (url: URL): string | undefined => {
// Redirects for deprecated vitepress URLs
if (url.pathname in urlRedirectMap) {
return `${urlRedirectMap[url.pathname]}${url.hash}`;
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"unocss": "^0.58.0",
"unplugin-vue-components": "^0.26.0",
"vite": "^4.4.12",
"vite-plugin-pwa": "^0.17.0",
"vitepress": "1.0.0-rc.31",
"vite-plugin-pwa": "^0.17.5",
"vitepress": "1.0.0-rc.40",
"workbox-window": "^7.0.0"
}
}
Loading
Loading