lang.ts 451 B

12345678910111213141516171819
  1. import { computed } from 'vue'
  2. import { useRoute } from 'vitepress'
  3. import { defaultLang } from '../constant'
  4. export const useLang = () => {
  5. const route = useRoute()
  6. return computed(() => {
  7. // the first part of the first slash
  8. const path = route.data?.relativePath
  9. let lang: string
  10. if (path?.includes('/')) {
  11. lang = path.split('/').shift()! || defaultLang
  12. } else {
  13. lang = defaultLang
  14. }
  15. return lang
  16. })
  17. }