From 7b58df3af3cd34ddee9b8fa00f118ce376d5ac95 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 7 Mar 2023 21:29:11 +0800 Subject: [PATCH] docs: cms, mpa, using vue edits --- docs/guide/cms.md | 49 +++++++++++++++++++++++++++++++++++++---- docs/guide/mpa-mode.md | 24 +++++++++++++++++++- docs/guide/using-vue.md | 16 ++++++++++---- 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/docs/guide/cms.md b/docs/guide/cms.md index ed6a07f7..92e61750 100644 --- a/docs/guide/cms.md +++ b/docs/guide/cms.md @@ -6,10 +6,51 @@ outline: deep ## General Workflow -## Integration Guides +Connecting VitePress to a CMS will largely revolve around [Dynamic Routes](/guide/routing#dynamic-routes). Make sure to understand how it works before proceeding. -If you have written a guide on integrating VitePress with a specific CMS, please use the "Edit this page" link below to submit it here! +Since each CMS will work differently, here we can only provide a generic workflow that you will need to adapt to your specific scenario. + +1. If your CMS requires authentication, create an `.env` file to store your API tokens and load it so: + + ```js + // posts/[id].paths.js + import { loadEnv } from 'vitepress' + + const env = loadEnv('', process.cwd()) + ``` + +2. Fetch the necessary data from the CMS and format it into proper paths data: + + ```js + export default { + async paths() { + // use respective CMS client library if needed + const data = await (await fetch('https://my-cms-api', { + headers: { + // token if necessary + } + })).json() -### Storyblok + return data.map(entry => { + return { + params: { id: entry.id, /* title, authors, date etc. */ }, + content: entry.content + } + }) + } + } + ``` -### Directus +3. Render the content in the page: + + ```md + # {{ $params.title }} + + - by {{ $params.author }} on {{ $params.date }} + + + ``` + +## Integration Guides + +If you have written a guide on integrating VitePress with a specific CMS, please use the "Edit this page" link below to submit it here! diff --git a/docs/guide/mpa-mode.md b/docs/guide/mpa-mode.md index e4bcd0f2..32c92036 100644 --- a/docs/guide/mpa-mode.md +++ b/docs/guide/mpa-mode.md @@ -1 +1,23 @@ -# MPA Mode +# MPA Mode + +MPA (Multi-Page Application) mode can be enabled via the command line via `vitepress build --mpa`, or via config through the `mpa: true` option. + +In MPA mode, all pages are rendered without any JavaScript included by default. As a result, the production site will likely have a better initial visit performance score from audit tools. + +However, due to the absence of SPA navigation, cross-page links will lead to full page reloads. Post-load navigations in MPA mode will not feel as instant as in SPA mode. + +Also note that no-JS-by-default also means you are essentially using Vue purely as a server-side templating language - no event handlers will be attached in the browser, so there will be no interactivity. To load client-side JavaScript, you can do so by using the special ` + +# Hello +``` + +Client scripts in all theme components will be bundled together, while client script for a specific page will be split for that page only. + +Notice that `