File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,29 +19,4 @@ document.addEventListener('DOMContentLoaded', function() {
1919 localStorage . setItem ( 'darkMode' , 'disabled' ) ;
2020 }
2121 } ) ;
22-
23- // --- 语言切换器逻辑 ---
24- const langSwitcher = document . getElementById ( 'lang-switcher' ) ;
25- if ( langSwitcher ) {
26- const currentPath = window . location . pathname ;
27- const currentLang = document . documentElement . lang . startsWith ( 'zh' ) ? 'zh' : 'en' ;
28- const otherLang = currentLang === 'en' ? 'zh' : 'en' ;
29-
30- // 构造目标语言的对应页面路径
31- let targetPath ;
32- if ( currentPath . startsWith ( `/${ currentLang } /` ) ) {
33- targetPath = currentPath . replace ( `/${ currentLang } /` , `/${ otherLang } /` ) ;
34- } else {
35- // 处理根目录跳转后的情况
36- targetPath = `/${ otherLang } /${ currentPath . substring ( 1 ) } ` ;
37- }
38-
39- // 如果在根目录(比如跳转前的 index.html),则直接指向目标语言首页
40- if ( currentPath === '/' || currentPath === '/index.html' ) {
41- targetPath = `/${ otherLang } /` ;
42- }
43-
44- langSwitcher . href = targetPath ;
45- }
46-
4722} ) ;
Original file line number Diff line number Diff line change 3636 < li > < a href ="{{ base_url }}/{{ lang }}/about.html " class ="{{ 'active' if nav_active == 'about' }} "> {{ T('nav_about') }}</ a > </ li >
3737 </ ul >
3838 < div class ="controls ">
39- < a href ="# " id ="lang-switcher " class ="lang-switcher "> {{ T('lang_switcher_text') }}</ a >
39+ <!-- 找到另一个语言的代码 -->
40+ {% set other_lang = 'zh' if lang == 'en' else 'en' %}
41+ <!-- 直接生成包含 base_url 的完整链接 -->
42+ < a href ="{{ base_url }}{{ alternate_paths[other_lang] }} " id ="lang-switcher " class ="lang-switcher "> {{ T('lang_switcher_text') }}</ a >
4043 < button id ="dark-mode-toggle " class ="dark-mode-toggle " aria-label ="{{ T('dark_mode_label') }} "> 🌓</ button >
4144 </ div >
4245 </ nav >
You can’t perform that action at this time.
0 commit comments