import{_ as i,c as a,ag as n,o as t}from"./chunks/framework.C1C4sYC0.js";const c=JSON.parse('{"title":"Connecting to a CMS","description":"","frontmatter":{"outline":"deep"},"headers":[],"relativePath":"guide/cms.md","filePath":"en/guide/cms.md","lastUpdated":1719560776000}'),e={name:"guide/cms.md"};function l(p,s,h,k,r,d){return t(),a("div",null,s[0]||(s[0]=[n(`
Connecting VitePress to a CMS will largely revolve around Dynamic Routes. Make sure to understand how it works before proceeding.
Since each CMS will work differently, here we can only provide a generic workflow that you will need to adapt to your specific scenario.
If your CMS requires authentication, create an .env file to store your API tokens and load it so:
// posts/[id].paths.js
import { loadEnv } from 'vitepress'
const env = loadEnv('', process.cwd())Fetch the necessary data from the CMS and format it into proper paths data:
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()
return data.map(entry => {
return {
params: { id: entry.id, /* title, authors, date etc. */ },
content: entry.content
}
})
}
}Render the content in the page:
# {{ $params.title }}
- by {{ $params.author }} on {{ $params.date }}
<!-- @content -->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!
`,7)]))}const E=i(e,[["render",l]]);export{c as __pageData,E as default};