Skip to content

Commit 3fa938a

Browse files
committed
fix: narrowing translations selector
1 parent 8c6f40a commit 3fa938a

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

docs/.vitepress/libs/nextPath.mts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ function nextPath(to: "en" | "ko", path: string): string {
88
: path.replace(/^\/en(?=\/|$)/, "/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
}

docs/.vitepress/theme/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)