@@ -3,6 +3,42 @@ import './style.css'
33
44let rootEnglishLabel = 'English'
55
6+ function dedupeLocaleMenuLinks ( ) {
7+ if ( typeof document === 'undefined' ) return
8+
9+ const containers = document . querySelectorAll (
10+ '.VPNavBarTranslations .items, .VPNavBarExtra .group.translations, .VPNavScreenTranslations .list'
11+ )
12+
13+ for ( const container of containers ) {
14+ const seen = new Set ( )
15+ const links = container . querySelectorAll ( 'a[href]' )
16+
17+ for ( const link of links ) {
18+ const label = link . textContent ?. trim ( ) || ''
19+ const href = link . getAttribute ( 'href' ) || ''
20+ const key = `${ label } ::${ href } `
21+
22+ if ( seen . has ( key ) ) {
23+ const removable = link . closest ( '.VPMenuLink, .item' )
24+ removable ?. remove ( )
25+ continue
26+ }
27+
28+ seen . add ( key )
29+ }
30+ }
31+ }
32+
33+ function queueLocaleMenuDedupe ( ) {
34+ if ( typeof window === 'undefined' ) return
35+ window . requestAnimationFrame ( ( ) => {
36+ window . requestAnimationFrame ( ( ) => {
37+ dedupeLocaleMenuLinks ( )
38+ } )
39+ } )
40+ }
41+
642function syncRootLocaleLabel ( siteData , href = '' ) {
743 const locales = siteData . value ?. locales
844 if ( ! locales ?. root || ! locales ?. zh ) return
@@ -28,10 +64,12 @@ export default {
2864 extends : DefaultTheme ,
2965 enhanceApp ( ctx ) {
3066 syncRootLocaleLabel ( ctx . siteData )
67+ queueLocaleMenuDedupe ( )
3168
3269 const previous = ctx . router . onAfterRouteChange
3370 ctx . router . onAfterRouteChange = async ( to ) => {
3471 syncRootLocaleLabel ( ctx . siteData , to )
72+ queueLocaleMenuDedupe ( )
3573 if ( previous ) {
3674 await previous ( to )
3775 }
0 commit comments