File tree Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -8,14 +8,21 @@ function nextPath(to: "en" | "ko", path: string): string {
88 : path . replace ( / ^ \/ e n (? = \/ | $ ) / , "/ko" ) ;
99}
1010
11- export function fixLangLinks ( pathname : string ) {
12- document
13- . querySelectorAll < HTMLAnchorElement > ( ' a.VPLink.link[href^="/en"]' )
14- . forEach ( ( a ) => a . setAttribute ( "href" , nextPath ( "en" , pathname ) ) ) ;
11+ export function fixLangLinks ( ) {
12+ const links = document . querySelectorAll < HTMLAnchorElement > (
13+ ".VPFlyout .group.translations .VPMenuLink > a.VPLink.link"
14+ ) ;
1515
16- document
17- . querySelectorAll < HTMLAnchorElement > (
18- 'a.VPLink.link[href^="/ko"], a.VPLink.link[href="/"]'
19- )
20- . forEach ( ( a ) => a . setAttribute ( "href" , nextPath ( "ko" , pathname ) ) ) ;
16+ links . forEach ( ( a ) => {
17+ const href = a . getAttribute ( "href" ) ! ;
18+
19+ if ( href . startsWith ( "/en" ) && ! href . startsWith ( "/en/" ) ) {
20+ a . setAttribute ( "href" , "/en/" ) ;
21+ return ;
22+ }
23+
24+ if ( href === "/ko" || href === "/ko/index.html" ) {
25+ a . setAttribute ( "href" , "/" ) ;
26+ }
27+ } ) ;
2128}
Original file line number Diff line number Diff line change @@ -14,9 +14,9 @@ export default {
1414 } ,
1515 enhanceApp ( { app, router, siteData } ) {
1616 if ( typeof window === "undefined" ) return ;
17- fixLangLinks ( window . location . pathname ) ;
18- router . onAfterRouteChanged = ( to ) => {
19- fixLangLinks ( to ) ;
17+ fixLangLinks ( ) ;
18+ router . onAfterRouteChanged = ( ) => {
19+ fixLangLinks ( ) ;
2020 } ;
2121 } ,
2222} satisfies Theme ;
You can’t perform that action at this time.
0 commit comments