Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pnxl opened this issue Mar 3, 2024 · 1 comment
Closed

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

pnxl opened this issue Mar 3, 2024 · 1 comment

Comments

@pnxl
Copy link

pnxl commented Mar 3, 2024

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: npm@10.2.4
  • Builder: -
  • User Config: devtools, ssr, css, modules, tailwindcss, app, content, generate
  • Runtime Modules: @nuxtjs/tailwindcss@6.8.0, @nuxt/content@2.12.0
  • 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

@farnabaz
Copy link
Member

farnabaz commented Mar 7, 2024

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

@farnabaz farnabaz closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants