|
|
|
@ -160,7 +160,7 @@ export async function createVitePressPlugin(
|
|
|
|
|
data = { ...siteData, head: [] }
|
|
|
|
|
}
|
|
|
|
|
data = serializeFunctions(data)
|
|
|
|
|
return `import { deserializeFunctions } from 'vitepress/client'
|
|
|
|
|
return `${deserializeFunctions.toString()}
|
|
|
|
|
export default deserializeFunctions(JSON.parse(${JSON.stringify(
|
|
|
|
|
JSON.stringify(data)
|
|
|
|
|
)}))`
|
|
|
|
@ -359,3 +359,18 @@ export async function createVitePressPlugin(
|
|
|
|
|
await dynamicRoutesPlugin(siteConfig)
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deserializeFunctions(value: any): any {
|
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
|
return value.map(deserializeFunctions)
|
|
|
|
|
} else if (typeof value === 'object' && value !== null) {
|
|
|
|
|
return Object.keys(value).reduce((acc, key) => {
|
|
|
|
|
acc[key] = deserializeFunctions(value[key])
|
|
|
|
|
return acc
|
|
|
|
|
}, {} as any)
|
|
|
|
|
} else if (typeof value === 'string' && value.startsWith('_vp-fn_')) {
|
|
|
|
|
return new Function(`return ${value.slice(7)}`)()
|
|
|
|
|
} else {
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|