Skip to content

Commit 7881e2c

Browse files
committed
fix: fix doc 404 close DevCloudFE#1310
1 parent 6d6fc5e commit 7881e2c

File tree

7 files changed

+35
-24
lines changed

7 files changed

+35
-24
lines changed

packages/devui-vue/docs/.vitepress/devui-theme/Layout.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import HomeFooter from './components/HomeFooter.vue'
1010
import { CONTRIBUTORS_MAP } from './components/PageContributorConfig'
1111
import PageContributor from './components/PageContributor.vue'
1212
import { Button } from '@devui/button';
13+
import { LANG_KEY, ZH_CN, EN_US } from './const';
1314
1415
const Home = defineAsyncComponent(() => import('./components/Home.vue'))
1516
@@ -81,13 +82,13 @@ const pageClasses = computed(() => {
8182
8283
// layout组件加载,初始化国际化语言.
8384
const result = location.pathname.match(/[a-zA-Z]*-[A-Z]*/)
84-
const langList = ['zh-CN', 'en-US']
85+
const langList = [ZH_CN, EN_US]
8586
8687
// 避免短横线分隔 (kebab-case)形式的路由命名导致读取语言错误
8788
if (result && langList.includes(result[0])) {
88-
localStorage.setItem('preferred_lang', result[0])
89+
localStorage.setItem(LANG_KEY, result[0])
8990
} else {
90-
localStorage.setItem('preferred_lang', navigator.language)
91+
localStorage.setItem(LANG_KEY, navigator.language)
9192
}
9293
9394
// Remove `__VP_STATIC_START__`

packages/devui-vue/docs/.vitepress/devui-theme/components/HomeFooter.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const { frontmatter } = useData()
2323
<ul>
2424
<li><a href="https://devui.design/" target="_blank">Ng DevUI</a></li>
2525
<li><a href="https://vue-devui.github.io/" target="_blank">Vue DevUI</a></li>
26-
<li><a href="https://react-devui.com/" target="_blank">React DevUI</a></li>
26+
<li><a href="https://react-devui.surge.sh/" target="_blank">React DevUI</a></li>
2727
<li><a href="https://devui.design/admin-page/home" target="_blank">Ng DevUI Admin</a></li>
2828
<li><a href="https://devui.design/icon/ruleResource" target="_blank">DevUI Icons</a></li>
2929
<li><a href="https://devcloudfe.github.io/devui-playground" target="_blank">DevUI Playground</a></li>

packages/devui-vue/docs/.vitepress/devui-theme/components/NavBar.vue

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ThemePicker from './ThemePicker.vue'
1313
import { Locale } from '@devui/locale'
1414
import enUS from '@devui/locale/lang/en-us'
1515
import zhCN from '@devui/locale/lang/zh-cn'
16+
import { LANG_KEY, CURRENT_LANG, ZH_CN, EN_US } from '../const'
1617
1718
// 主题切换
1819
const THEME_MAP = {
@@ -38,33 +39,33 @@ watch(currentTheme, (newVal) => {
3839
})
3940
4041
// 国际化
41-
const defaultLanguage = ref(localStorage.getItem('preferred_lang'))
42+
const defaultLanguage = ref(CURRENT_LANG)
4243
function useTranslation(target) {
4344
defaultLanguage.value = target
44-
localStorage.setItem('preferred_lang', target)
45-
if (target === 'en-US') {
46-
location.pathname = `/en-US${location.pathname}`
47-
} else if (target === 'zh-CN') {
48-
location.pathname = `${location.pathname.split('/en-US')[1]}`
45+
localStorage.setItem(LANG_KEY, target)
46+
if (target === EN_US) {
47+
location.pathname = `/${EN_US}${location.pathname}`
48+
} else if (target === ZH_CN) {
49+
location.pathname = location.pathname.split(`/${EN_US}`)[1];
4950
}
5051
}
5152
5253
defineEmits(['toggle'])
5354
5455
const LANG_MAP = {
55-
'zh-CN': '中文',
56-
'en-US': 'English',
56+
[ZH_CN]: '中文',
57+
[EN_US]: 'English',
5758
}
5859
59-
const currentLang = ref('zh-CN');
60+
const currentLang = ref(CURRENT_LANG);
6061
const app = getCurrentInstance();
6162
const switchLang = () => {
62-
if (currentLang.value === 'zh-CN') {
63-
Locale.use('en-US', enUS);
64-
currentLang.value = 'en-US';
63+
if (currentLang.value === ZH_CN) {
64+
Locale.use(EN_US, enUS);
65+
currentLang.value = EN_US;
6566
} else {
66-
Locale.use('zh-CN', zhCN);
67-
currentLang.value = 'zh-CN';
67+
Locale.use(ZH_CN, zhCN);
68+
currentLang.value = ZH_CN;
6869
}
6970
app.appContext.config.globalProperties.langMessages.value = Locale.messages();
7071
};
@@ -88,10 +89,10 @@ const switchLang = () => {
8889
<div
8990
class="custom-nav-item ml-m"
9091
style="font-size: 0"
91-
@click="() => useTranslation(defaultLanguage === 'zh-CN' ? 'en-US' : 'zh-CN')"
92+
@click="() => useTranslation(defaultLanguage === ZH_CN ? EN_US : ZH_CN)"
9293
v-if="false"
9394
>
94-
<ZhLang v-if="defaultLanguage === 'zh-CN'"></ZhLang>
95+
<ZhLang v-if="defaultLanguage === ZH_CN"></ZhLang>
9596
<EnLang v-else></EnLang>
9697
</div>
9798
<div

packages/devui-vue/docs/.vitepress/devui-theme/components/NavLinks.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { useRepo } from '../composables/repo'
66
import NavLink from './NavLink.vue'
77
import NavDropdownLink from './NavDropdownLink.vue'
88
import enNav from '../../config/enNav'
9+
import { CURRENT_LANG, ZH_CN } from '../const'
910
1011
const { theme } = useData()
1112
const localeLinks = useLocaleLinks()
1213
const repo = useRepo()
1314
const show = computed(() => theme.value.nav || repo.value || localeLinks.value)
14-
let translationTheme = computed( () => localStorage.getItem('preferred_lang') === 'zh-CN' ? theme.value.nav : enNav )
15+
let translationTheme = computed( () => CURRENT_LANG === ZH_CN ? theme.value.nav : enNav )
1516
</script>
1617

1718
<template>

packages/devui-vue/docs/.vitepress/devui-theme/components/PageToc.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import { ref, computed } from 'vue'
33
import { useToc } from '../composables/useToc'
44
import { useActiveSidebarLinks } from '../composables/activeBar'
5+
import { CURRENT_LANG, ZH_CN } from '../const'
56
67
const headers = useToc()
78
const marker = ref()
89
const container = ref()
910
// 滚动监听
1011
useActiveSidebarLinks(container, marker)
1112
const forwardText = computed(() => {
12-
return localStorage.getItem('preferred_lang') === 'zh-CN' ? '快速前往' : 'Forward'
13+
return CURRENT_LANG === ZH_CN ? '快速前往' : 'Forward'
1314
})
1415
</script>
1516

packages/devui-vue/docs/.vitepress/devui-theme/composables/sideBar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useActiveSidebarLinks } from '../composables/activeSidebarLink';
44
import { getSideBarConfig } from '../support/sideBar';
55
import enSidebar from '../../config/enSidebar'
66
import sidebar from '../../config/sidebar'
7+
import { CURRENT_LANG, ZH_CN } from '../const';
8+
79
export function useSideBar() {
810
const route = useRoute();
911
const { site } = useData();
@@ -17,12 +19,12 @@ export function useSideBar() {
1719
if (frontSidebar === false) {
1820
return [];
1921
}
20-
// if it's `atuo`, render headers of the current page
22+
// if it's `auto`, render headers of the current page
2123
if (frontSidebar === 'auto') {
2224
return resolveAutoSidebar(headers, sidebarDepth);
2325
}
2426
// now, there's no sidebar setting at frontmatter; let's see the configs
25-
const themeSidebar = getSideBarConfig(localStorage.getItem('preferred_lang') === 'zh-CN' ? sidebar : enSidebar , route.data.relativePath);
27+
const themeSidebar = getSideBarConfig(CURRENT_LANG === ZH_CN ? sidebar : enSidebar , route.data.relativePath);
2628
if (themeSidebar === false) {
2729
return [];
2830
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const ZH_CN = 'zh-CN';
2+
export const EN_US = 'en-US';
3+
export const DEFAULT_LANG = ZH_CN;
4+
export const LANG_KEY = 'vue-devui-preferred-lang';
5+
export const CURRENT_LANG = localStorage.getItem(LANG_KEY) || DEFAULT_LANG;

0 commit comments

Comments
 (0)