Skip to content

Commit

Permalink
英文版首页增加中文跳转提醒;
Browse files Browse the repository at this point in the history
  • Loading branch information
hslr-s committed Jul 26, 2024
1 parent 5bb9836 commit 7b33074
Show file tree
Hide file tree
Showing 5 changed files with 749 additions and 615 deletions.
23 changes: 23 additions & 0 deletions docs/.vitepress/src/components/langChange.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup>
import Swal from 'sweetalert2';
const userLang = navigator.language || navigator.userLanguage;
const isChinese = userLang.startsWith('zh');
if (isChinese) {
Swal.fire({
title: '语言切换',
text: '检测到您的浏览器语言为中文,是否跳转到中文站点?',
icon: 'question',
showCancelButton: true,
confirmButtonText: '',
cancelButtonText: ''
}).then((result) => {
if (result.isConfirmed) {
window.location.href = '/zh_cn/';
}
});
}
</script>
<template>
<div />
</template>
21 changes: 21 additions & 0 deletions docs/.vitepress/src/js/langChange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Swal from 'sweetalert2';

document.addEventListener('DOMContentLoaded', () => {
const userLang = navigator.language || navigator.userLanguage;
const isChinese = userLang.startsWith('zh');

if (isChinese) {
Swal.fire({
title: '语言切换',
text: '检测到您的浏览器语言为中文,是否跳转到中文站点?',
icon: 'question',
showCancelButton: true,
confirmButtonText: '是',
cancelButtonText: '否'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = '/zh/';
}
});
}
});
13 changes: 2 additions & 11 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,9 @@ If there are any inaccuracies, please forgive.If you are willing, you can click
}
</style>

<LangChange/>

<script setup>

(function() {
const userLang = navigator.language || navigator.userLanguage;
const isChinese = userLang.startsWith('zh');

if (isChinese) {
const userConsent = confirm('检测到您的浏览器语言为中文,是否跳转到中文站点?');
if (userConsent) {
window.location.href = '/zh_cn/';
}
}
})();
import LangChange from '../docs/.vitepress/src/components/langChange.vue';
</script>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"docs:preview": "vitepress preview docs"
},
"dependencies": {
"markdown-it-task-lists": "^2.1.1"
"markdown-it-task-lists": "^2.1.1",
"sweetalert2": "^11.12.3"
}
}
Loading

0 comments on commit 7b33074

Please sign in to comment.