Files
vuepress/packages/@vuepress/core/lib/client/dataMixin.js
T
ULIVZandGitHub e5d8ed4655 feat: refine node api (#1395)
- fix($core): markdown slot doesn‘t work. (regression of c85f62d)
- docs: fresh Node.JS API.
- test: official plugins.
2019-03-04 23:46:13 +08:00

38 lines
965 B
JavaScript

/* global VUEPRESS_TEMP_PATH */
import GLobalVue from 'vue'
export default function dataMixin (I18n, siteData, Vue = GLobalVue) {
prepare(siteData)
Vue.$vuepress.$set('siteData', siteData)
if (module.hot) {
module.hot.accept(VUEPRESS_TEMP_PATH + '/internal/siteData.js', () => {
prepare(siteData)
Vue.$vuepress.$set('siteData', siteData)
})
}
const I18nConstructor = I18n(Vue.$vuepress.$get('siteData'))
const i18n = new I18nConstructor()
const descriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(i18n))
const computed = {}
Object.keys(descriptors).reduce((computed, key) => {
if (key.startsWith('$')) {
computed[key] = descriptors[key].get
}
return computed
}, computed)
return { computed }
}
function prepare (siteData) {
if (siteData.locales) {
Object.keys(siteData.locales).forEach(path => {
siteData.locales[path].path = path
})
}
Object.freeze(siteData)
}