Nuxt Generate does not generate everything in 'content' folder
Environment
- Operating System: Windows_NT
- Node Version: v20.11.1
- Nuxt Version: 3.10.3
- CLI Version: 3.10.1
- Nitro Version: 2.9.0
- Package Manager: [email protected]
- Builder: -
- User Config: devtools, ssr, css, modules, tailwindcss, app, content, generate
- Runtime Modules: @nuxtjs/[email protected], @nuxt/[email protected]
- Build Modules: -
Reproduction
Reproduction repo available here: https://github.com/pnxl/notes-repro
Clone, install packages, and deploy on a static host (Vercel, CloudFlare, Netlify, etc.) You will see that you can visit /digital-gardening (because there's a link to it in /index), but not /test (presumably because there are no router-links pointing to that page)
Describe the bug
Doing nuxt generate only generates items in the content folder that has a link to it - without a link, the pages do not get generated. Notice how /digital-gardening is generated, but not /test. There's a link to /digital-gardening on index, but not to test.
Previously on Content v1 and Nuxt 2, I would use this to generate all routes:
generate: {
async routes() {
const { $content } = require("@nuxt/content");
const files = await $content({ deep: true }).only(["path"]).fetch();
return files.map((file: { path: string }) =>
file.path === "/index" ? "/" : file.path,
);
},
},
But how could I do this with Nuxt 3 + Content v2? Help is appreciated.
Additional context
No response
Logs
No response
Content module uses Nuxt API routes to lookup the proper content and render in pages. When you generate your website Nuxt generates a chunk for each page that is accessible via crawling, And there is no API in generated website. As the result the content API's are missing in your production and you've got missign content.
What you can do is to add aoute rule for the test page in nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/': { prerender: true },
'/test': { prerender: true }
}
})