docs: pre-render component-meta routes

This commit is contained in:
Sébastien Chopin
2023-05-20 19:13:58 +02:00
parent d3e5f4e15d
commit 8a0a5d8ba0
4 changed files with 22 additions and 3 deletions

View File

@@ -10,7 +10,16 @@ export async function fetchComponentMeta (name: string) {
if (state.value[name]) { return state.value[name] }
// Store promise to avoid multiple calls
state.value[name] = $fetch(`/api/component-meta/${name}`).then((meta) => {
// add to nitro prerender
if (process.server) {
const event = useRequestEvent()
event.node.res.setHeader(
'x-nitro-prerender',
[event.node.res.getHeader('x-nitro-prerender'), `/api/component-meta/${name}.json`].filter(Boolean).join(',')
)
}
state.value[name] = $fetch(`/api/component-meta/${name}.json`).then((meta) => {
state.value[name] = meta
})

View File

@@ -31,7 +31,7 @@ export default defineNuxtConfig({
includeWorkspace: true
},
routeRules: {
'/': { redirect: '/getting-started' },
'/': { redirect: '/getting-started' }
},
generate: {
routes: ['/getting-started']

View File

@@ -59,7 +59,7 @@
"@vueuse/nuxt": "^10.1.2",
"eslint": "^8.40.0",
"nuxt": "^3.4.3",
"nuxt-component-meta": "^0.5.1",
"nuxt-component-meta": "^0.5.2",
"nuxt-lodash": "^2.4.1",
"standard-version": "^9.5.0",
"unbuild": "^1.2.1",

View File

@@ -6800,6 +6800,16 @@ nuxt-component-meta@^0.5.1:
typescript "^5.0.2"
vue-component-meta "^1.2.0"
nuxt-component-meta@^0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/nuxt-component-meta/-/nuxt-component-meta-0.5.2.tgz#11433aea988740619846852ed7e49a7dd703404a"
integrity sha512-tjX2JaSRUm9tlxHCZ6cRauJnRm1zPMrPaoHj0dKtwHHXjrcp1+Ou2aL2SjD22mnaZ5ZulcEbyvsqp/oMwVldVQ==
dependencies:
"@nuxt/kit" "^3.3.1"
scule "^1.0.0"
typescript "^5.0.2"
vue-component-meta "^1.2.0"
nuxt-config-schema@^0.4.6:
version "0.4.6"
resolved "https://registry.yarnpkg.com/nuxt-config-schema/-/nuxt-config-schema-0.4.6.tgz#4ff9b912648ddab8202c232040d5d38d0f14bef3"