From 47a0e940a5e75d7a8859b1e7857cbbd8f0bd2268 Mon Sep 17 00:00:00 2001 From: oliv37 Date: Mon, 27 Nov 2023 23:22:40 +0100 Subject: [PATCH] docs: dynamic site config --- docs/reference/site-config.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/reference/site-config.md b/docs/reference/site-config.md index b5e124d2..b7d34fa1 100644 --- a/docs/reference/site-config.md +++ b/docs/reference/site-config.md @@ -24,6 +24,29 @@ export default { } ``` +In case of dynamic config, you can also default export a function: + +```js +export default async () => { + const posts = await (await fetch('https://my-cms.com/blog-posts')).json() + + return { + lang: 'en-US', + title: 'VitePress', + description: 'Vite & Vue powered static site generator.', + // theme config options + themeConfig: { + sidebar: [ + ...posts.map(post => ({ + text: post.name, + link: `/posts/${post.name}` + })) + ] + } + }; +} +``` + ### Config Intellisense Using the `defineConfig` helper will provide TypeScript-powered intellisense for config options. Assuming your IDE supports it, this should work in both JavaScript and TypeScript.