|
945 | 945 |
|
946 | 946 | checkAndRedirect(preferredLang) { |
947 | 947 | const currentPath = window.location.pathname; |
948 | | - const currentFile = currentPath.split('/').pop(); |
| 948 | + const currentFile = currentPath.split('/').pop() || 'index.html'; |
| 949 | + |
| 950 | + // Special handling for index pages |
| 951 | + if (currentFile === 'index.html' || currentFile === 'index-cn.html' || currentPath === '/') { |
| 952 | + if (preferredLang === 'cn' && currentFile !== 'index-cn.html') { |
| 953 | + window.location.pathname = '/index-cn.html'; |
| 954 | + return; |
| 955 | + } else if (preferredLang === 'en' && currentFile === 'index-cn.html') { |
| 956 | + window.location.pathname = '/index.html'; |
| 957 | + return; |
| 958 | + } |
| 959 | + } |
949 | 960 |
|
950 | 961 | // Check if we're on a post page |
951 | 962 | if ( |
952 | 963 | currentFile && |
953 | 964 | currentFile.endsWith('.html') && |
954 | 965 | currentFile !== 'index.html' && |
| 966 | + currentFile !== 'index-cn.html' && |
955 | 967 | currentFile !== 'about.html' && |
956 | 968 | currentFile !== '404.html' |
957 | 969 | ) { |
|
1003 | 1015 |
|
1004 | 1016 | // Handle page redirects for language switching |
1005 | 1017 | const currentPath = window.location.pathname; |
1006 | | - const currentFile = currentPath.split('/').pop(); |
| 1018 | + const currentFile = currentPath.split('/').pop() || 'index.html'; |
| 1019 | + |
| 1020 | + // Special handling for index pages |
| 1021 | + if (currentFile === 'index.html' || currentFile === 'index-cn.html' || currentPath === '/') { |
| 1022 | + if (lang === 'cn') { |
| 1023 | + window.location.pathname = '/index-cn.html'; |
| 1024 | + } else { |
| 1025 | + window.location.pathname = '/index.html'; |
| 1026 | + } |
| 1027 | + return; |
| 1028 | + } |
1007 | 1029 |
|
1008 | 1030 | // Check if we're on a post page |
1009 | 1031 | if ( |
1010 | 1032 | currentFile && |
1011 | 1033 | currentFile.endsWith('.html') && |
1012 | 1034 | currentFile !== 'index.html' && |
| 1035 | + currentFile !== 'index-cn.html' && |
1013 | 1036 | currentFile !== 'about.html' && |
1014 | 1037 | currentFile !== '404.html' |
1015 | 1038 | ) { |
|
0 commit comments