11import DefaultTheme from 'vitepress/theme'
22import type { Theme } from 'vitepress'
33import { h , onMounted , watch , nextTick } from 'vue'
4- import { useRoute } from 'vitepress'
4+ import { useRoute , useRouter } from 'vitepress'
55import GitHubStars from './components/GitHubStars.vue'
66import TypePHPSnippet from './components/TypePHPSnippet.vue'
77import './custom.css'
@@ -43,6 +43,37 @@ function enableTableSorting() {
4343 } )
4444}
4545
46+ function checkAndRedirect ( path : string ) : boolean {
47+ if ( typeof window === 'undefined' ) return false
48+
49+ if ( path . startsWith ( '/docs/blog/' ) ) {
50+ const target = path . replace ( '/docs/blog/' , '/blog/' )
51+ window . location . replace ( target + window . location . search + window . location . hash )
52+ return true
53+ }
54+
55+ const docsSections = [
56+ '/getting-started' ,
57+ '/core-concepts' ,
58+ '/supported-types' ,
59+ '/generics' ,
60+ '/testing' ,
61+ '/advanced' ,
62+ '/production' ,
63+ '/troubleshooting' ,
64+ ]
65+
66+ for ( const section of docsSections ) {
67+ if ( path . startsWith ( section ) && ! path . startsWith ( '/docs/' ) ) {
68+ const target = '/docs' + path + window . location . search + window . location . hash
69+ window . location . replace ( target )
70+ return true
71+ }
72+ }
73+
74+ return false
75+ }
76+
4677export default {
4778 extends : DefaultTheme ,
4879 Layout ( ) {
@@ -57,6 +88,10 @@ export default {
5788 const route = useRoute ( )
5889
5990 onMounted ( ( ) => {
91+ if ( checkAndRedirect ( window . location . pathname ) ) {
92+ return
93+ }
94+
6095 enableTableSorting ( )
6196
6297 if ( typeof window !== 'undefined' && 'serviceWorker' in navigator ) {
@@ -70,10 +105,12 @@ export default {
70105
71106 watch (
72107 ( ) => route . path ,
73- ( ) => {
74- nextTick ( ( ) => {
75- enableTableSorting ( )
76- } )
108+ ( newPath ) => {
109+ if ( ! checkAndRedirect ( newPath ) ) {
110+ nextTick ( ( ) => {
111+ enableTableSorting ( )
112+ } )
113+ }
77114 }
78115 )
79116 }
0 commit comments