element-plus/docs/.vitepress/vitepress/composables/lang.ts
三咲智子 d28d0701d7
docs: improve code (#5040)
* docs: remove unused code

* refactor(docs): improve code
2021-12-30 19:00:11 +08:00

20 lines
436 B
TypeScript

import { computed } from 'vue'
import { useRoute } from 'vitepress'
import { defaultLang } from '../constant'
export const useLang = () => {
const route = useRoute()
return computed(() => {
// the first part of the first slash
const path = route.data?.relativePath
let lang: string
if (path?.includes('/')) {
lang = path.split('/').shift()!
} else {
lang = defaultLang
}
return lang
})
}