feat: add locale

This commit is contained in:
2023-04-16 18:09:13 +08:00
parent f394f48853
commit 9f19ed8c74
25 changed files with 1434 additions and 944 deletions

42
.vitepress/config.ts Normal file
View File

@ -0,0 +1,42 @@
import { fileURLToPath } from 'url'
import { resolve } from 'path'
import { defineConfig } from 'vitepress'
import vueJsxPlugin from '@vitejs/plugin-vue-jsx'
import VitePluginVitepressDemo from 'vite-plugin-vitepress-demo'
import getEnUSConfig from './config/en-US'
import getZhCNConfig from './config/zh-CN'
import { getRewrites } from './config/rewrites'
const baseSrc = fileURLToPath(new URL('./', import.meta.url))
export default defineConfig({
rewrites: getRewrites(),
mpa: true,
lang: 'en-US',
locales: {
'zh-CN': {
lang: 'zh-CN',
title: 'vue3组件库站点',
label: '简体中文',
description: 'vue3组件库站点',
themeConfig: getZhCNConfig()
},
root: {
lang: 'en-US',
title: 'vue3 component library site',
label: 'English',
description: 'vue3 component library site',
themeConfig: getEnUSConfig()
}
},
vite: {
plugins: [vueJsxPlugin(), VitePluginVitepressDemo()],
resolve: {
alias: {
'antd-tiny-vue': resolve(baseSrc, '../components')
}
},
server: {
port: 1199
}
}
})

View File

@ -0,0 +1,9 @@
import type { DefaultTheme } from 'vitepress'
import { getNav } from './nav'
import { getSidebar } from './sidebar'
export default (): DefaultTheme.Config => ({
nav: getNav(),
sidebar: getSidebar(),
i18nRouting: true
})

View File

@ -0,0 +1,10 @@
import type { DefaultTheme } from 'vitepress'
export const getNav = (): DefaultTheme.NavItem[] => {
return [
{
text: 'Components',
link: '/components/'
}
]
}

View File

@ -0,0 +1,18 @@
import type { DefaultTheme } from 'vitepress'
const componentsDir = `/components/`
export const getSidebar = (): DefaultTheme.Sidebar => {
return {
'/components/': [
{
text: 'Button',
link: `${componentsDir}button/`
},
{
text: 'ConfigProvider',
link: `${componentsDir}config-provider/`
}
]
}
}

View File

@ -0,0 +1,9 @@
export const getRewrites = (): Record<string, string> => {
return {
'site/index.md': 'index.md',
'site/index.zh-CN.md': 'zh-CN/index.md',
'site/components/index.md': 'components/index.md',
'site/components/index.zh-CN.md': 'zh-CN/components/index.md',
'components/:btn/index.zh-CN.md': 'zh-CN/components/:btn/index.md'
}
}

View File

@ -0,0 +1,9 @@
import type { DefaultTheme } from 'vitepress'
import { getNav } from './nav'
import { getSidebar } from './sidebar'
export default (): DefaultTheme.Config => ({
nav: getNav(),
sidebar: getSidebar(),
i18nRouting: true
})

View File

@ -0,0 +1,10 @@
import type { DefaultTheme } from 'vitepress'
export const getNav = (): DefaultTheme.NavItem[] => {
return [
{
text: '组件',
link: '/zh-CN/components/'
}
]
}

View File

@ -0,0 +1,17 @@
import type { DefaultTheme } from 'vitepress'
const componentsDir = `/zh-CN/components/`
export const getSidebar = (): DefaultTheme.Sidebar => {
return {
'/zh-CN/components/': [
{
text: 'Button 按钮',
link: `${componentsDir}button/`
},
{
text: 'ConfigProvider',
link: `${componentsDir}config-provider/`
}
]
}
}

15
.vitepress/theme/index.ts Normal file
View File

@ -0,0 +1,15 @@
import type { Theme } from 'vitepress'
// eslint-disable-next-line import/no-named-as-default
import DefaultTheme from 'vitepress/theme'
import { AntdTheme } from 'vite-plugin-vitepress-demo/theme'
// @ts-expect-error this is a local module
import Antd from 'antd-tiny-vue'
export default {
...DefaultTheme,
enhanceApp(ctx) {
DefaultTheme.enhanceApp?.(ctx)
ctx.app.component('Demo', AntdTheme)
ctx.app.use(Antd)
}
} as Theme