Files
AstralRinth/docs/.vitepress/theme/index.js
Sasha Sorokin 5051ad91ff Fix ambiguous default export (#113)
Currently Omorphia's index file has both the default and named exports.
While this is totally supported by native ESM, it's pretty hard for
transpilers to process and may lead to situations where named exports
cannot be imported directly, requiring destructuring on the default
import. For this and just consistency reasons, you'd usually avoid
mixing default and named exports.

This commit removes the default export, making it just an another named
export called `plugin`.

BREAKING CHANGE: plugin is now exported using `plugin` export, rather
than the default export.
2023-11-13 13:36:07 -07:00

51 lines
1.5 KiB
JavaScript

import { localeDefinitions } from '@modrinth/omorphia-dev/locales/index.js'
import { createPlugin } from '@vintl/vintl/plugin'
import { plugin as Omorphia } from 'omorphia'
import DefaultTheme from 'vitepress/theme'
import { createVNode } from 'vue'
import DemoContainer from './DemoContainer.vue'
import LanguageSwitcher from './LanguageSwitcher.vue'
import './compat.scss'
import './style.scss'
/** @type {import('vitepress').Theme} */
export default {
...DefaultTheme,
enhanceApp(ctx) {
ctx.app.use(Omorphia)
ctx.app.component('DemoContainer', DemoContainer)
ctx.app.use(
createPlugin({
controllerOpts: {
locales: Object.keys(localeDefinitions).map((tag) => ({ tag })),
listen: {
async localeload(event) {
const locale = event.locale.tag
if (!Object.hasOwn(localeDefinitions, locale)) {
throw new Error(`Unknown locale: ${locale}`)
}
try {
const { messages } = await localeDefinitions[locale].importFunction()
event.addMessages(messages)
} catch (err) {
console.error(`Failed to load locale: ${locale}`, err)
}
},
},
defaultMessageOrder: ['locale', 'descriptor'],
},
globalMixin: false,
})
)
},
Layout() {
return createVNode(DefaultTheme.Layout, null, {
'sidebar-nav-before'() {
return createVNode(LanguageSwitcher)
},
})
},
}