Skip to content

Commit

Permalink
refactor(docs): abstract client js
Browse files Browse the repository at this point in the history
  • Loading branch information
NWYLZW committed Nov 12, 2024
1 parent f8e7ef7 commit 0b50e9c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
25 changes: 25 additions & 0 deletions docs/.vitepress/theme/index.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { loader } from '@guolao/vue-monaco-editor'

loader.config({
paths: {
vs: 'https://cdn.jsdelivr.net/npm/[email protected]/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']
})
26 changes: 1 addition & 25 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -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/[email protected]/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 {
Expand Down

0 comments on commit 0b50e9c

Please sign in to comment.