diff --git a/docs/.vitepress/theme/index.client.ts b/docs/.vitepress/theme/index.client.ts new file mode 100644 index 0000000..847e4a8 --- /dev/null +++ b/docs/.vitepress/theme/index.client.ts @@ -0,0 +1,25 @@ +import { loader } from '@guolao/vue-monaco-editor' + +loader.config({ + paths: { + vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.0/min/vs' + } +}) + +// observe html lang change and update availableLanguages +new MutationObserver(async () => { + loader.config({ + 'vs/nls': { + availableLanguages: { + '*': { + 'zh-Hans': 'zh-cn', + 'zh-Hant': 'zh-tw', + en: 'en' + }[document.querySelector('html')?.lang || 'zh-Hans'] + } + } + }) +}).observe(document.querySelector('html')!, { + attributes: true, + attributeFilter: ['lang'] +}) diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index 4183ed7..752208f 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -1,33 +1,9 @@ import './index.css' -import { loader } from '@guolao/vue-monaco-editor' - import DefaultTheme from 'vitepress/theme' if (!import.meta.env.SSR) { - loader.config({ - paths: { - vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.52.0/min/vs' - } - }) - - // observe html lang change and update availableLanguages - new MutationObserver(async () => { - loader.config({ - 'vs/nls': { - availableLanguages: { - '*': { - 'zh-Hans': 'zh-cn', - 'zh-Hant': 'zh-tw', - en: 'en' - }[document.querySelector('html')?.lang || 'zh-Hans'] - } - } - }) - }).observe(document.querySelector('html')!, { - attributes: true, - attributeFilter: ['lang'] - }) + import('./index.client') } export default {