-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
dataMixin.js
37 lines (31 loc) · 942 Bytes
/
dataMixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* global VUEPRESS_TEMP_PATH */
import Vue from 'vue'
export default function dataMixin (I18n, siteData) {
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)
}