You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vitepress/lib/app/composables/siteData.js

26 lines
479 B

import serialized from '@siteData'
import { hot } from 'vite/hmr'
import { ref, readonly } from 'vue'
/**
* @param {string} data
* @returns {any}
*/
const parse = (data) => readonly(JSON.parse(data))
/**
* @type {import('vue').Ref<import('src').SiteData>}
*/
export const siteDataRef = ref(parse(serialized))
export function useSiteData() {
return siteDataRef
}
// hmr
if (__DEV__) {
hot.accept('/@siteData', (m) => {
siteDataRef.value = parse(m.default)
})
}