garethredfern/nuxt-basic-blog

Doesn't generate blog routes in dist folder

Closed this issue · 2 comments

Excellent example, except, when running npm run generate, the individual blog folders aren't generated in full static mode, is there a way to achieve this?

Hey @sts-ryan-holton 👋, I think I came across the same thing (at least I hope I'm interpreting what you've said correctly).

This StackOverflow pointed me in the right direction: https://stackoverflow.com/questions/56927438/nuxt-generate-throws-error-for-dynamic-page-nuxt-js

You may need to add the dynamic routes in the nuxt.config file under the generate options. Further information on the generate config can be found in Nuxt's documentation.

# nuxt.config.js
generate: {
    routes() {
      // getRoutes is imported at the top of the nuxt.config file
      return getRoutes()
    }
 }
# generateRoutes.js

export default async () => {
    const { $content } = require('@nuxt/content')
    const posts = await $content('posts', { deep: true }).only(['path']).fetch()

    // Add blog pages routes
    const totalBlogPages = Math.ceil(posts.length / 5)
    const blogsPaginationRoutes = []
    for (let i = 1; i <= totalBlogPages; i++) {
        blogsPaginationRoutes.push(`/scripts/page/${i}`)
    }

    // Concat routes and pagination
    const routes = [...blogsPaginationRoutes, ...posts]

    return routes
}

Hope this helps!

@sts-ryan-holton did what @aaronguernsey suggested fix your issue? I haven't run into this problem but all the content is served from a single content folder in the example.