nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.08k stars 624 forks source link

Nuxt Generate does not generate everything in 'content' folder #2577

Closed pnxl closed 4 months ago

pnxl commented 6 months ago

Environment

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

farnabaz commented 6 months ago

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 }
  }
})