decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.9k stars 3.04k forks source link

Nuxtjs Documentation cant get it to work #2659

Closed enricoschaaf closed 8 months ago

enricoschaaf commented 5 years ago

Describe the bug After following the guide on how to set up nuxtjs + netlify-cms i will get the ERROR Could not resolve routes when running the generate command. Also i get FATAL Invalid left-hand side expression in prefix operation.

To Reproduce To reproduce you basiclly just have to follow the docs on how to set up nuxt and netlify cms, the error happens to me when i start to add generate: { routes: function () { const fs = require('fs'); return fs.readdirSync('./assets/content/blog').map(file => { return { route:/blog/${file.slice(2, -5)}, // Remove the .json from the end of the filename payload: require(./assets/content/blog/${file}), }; }); }, },

Expected behavior I expected this part of the code to generate the routes for the blog articles

Screenshots Capture )

Applicable Versions:

CMS configuration `backend: name: git-gateway branch: master

media_folder: static/img public_folder: /img

collections:

Additional context Full github repository https://github.com/enricoschaaf/github-issue

enricoschaaf commented 5 years ago

I closed it because I found the instruction as a template on Twitter by the same user. https://github.com/xdesro/nuxt-netlify-cms-starter Don't know what I did wrong but this solved it for me. Maybe it could be linked in the docs.

nttdataxd commented 4 years ago

I am also getting an error after following the docs and trying to run generate, was there ever any fix to this or is https://github.com/xdesro/nuxt-netlify-cms-starter now the real starter?

terrencechambersvmlyr commented 4 years ago

I have the same issue. One of the things I noticed is the directory ./assets/content/blog doesn't exist and was never instructed to setup so why is the directory set to there? The instructions say ./content/blog.

Another thing. I setup _slug.vue. Locally when running npm run dev, I can access the page at localhost:3000/whater-the-slug-name-is but online it does not work.

brachkow commented 3 years ago

Examples from docs still lead to this errors. For myself I resolved this issue via

generate: {
    async routes() {
      const contentPaths = ['docs'];

      const files = [];
      contentPaths.forEach(async (path) => {
        const file = await $content(path).fetch();
        files.push(file);
      });

      const generated = files.map((file) => {
        return {
          route: file.path === '/index' ? '/' : file.path,
          payload: fs.readFileSync(`./content/${file.path}${file.extension}`, 'utf-8'),
        };
      });

      return generated;
    },
  },
erezrokah commented 3 years ago

Re-opening the issue until we can verify the guide

s-en-o commented 3 years ago

(Context: deploying with Netlify by following docs from NetlifyCMS with Nuxt)

I tried https://github.com/xdesro/nuxt-netlify-cms-starter but still throwing error (also in Vercel) and solution suggested by @brachkow is the one that works for me. (Quoted below).

Examples from docs still lead to this errors. For myself I resolved this issue via

generate: {
    async routes() {
      const contentPaths = ['docs'];

      const files = [];
      contentPaths.forEach(async (path) => {
        const file = await $content(path).fetch();
        files.push(file);
      });

      const generated = files.map((file) => {
        return {
          route: file.path === '/index' ? '/' : file.path,
          payload: fs.readFileSync(`./content/${file.path}${file.extension}`, 'utf-8'),
        };
      });

      return generated;
    },
  },

Thanks @brachkow 🙏🏼

martinjagodic commented 8 months ago

Closing as outdated