onecrayon / gridsome-plugin-feed

Generate an RSS, Atom, and/or JSON feed for your Gridsome site
13 stars 15 forks source link

TypeError: entry.date.toUTCString is not a function #7

Closed rasulkireev closed 3 years ago

rasulkireev commented 4 years ago

When I run gridsome develop I get the following error:

enerate RSS feed at /feed.xml
TypeError: entry.date.toUTCString is not a function
    at /Users/rasulkireev/git/webdev/gridsome-personal-webite/node_modules/feed/lib/rss2.js:86:48
    at Array.map (<anonymous>)
    at Object.default (/Users/rasulkireev/git/webdev/gridsome-personal-webite/node_modules/feed/lib/rss2.js:68:15)
    at Feed.rss2 (/Users/rasulkireev/git/webdev/gridsome-personal-webite/node_modules/feed/lib/feed.js:18:56)
    at /Users/rasulkireev/git/webdev/gridsome-personal-webite/node_modules/gridsome-plugin-feed/index.js:104:60
    at Plugins.run (/Users/rasulkireev/git/webdev/gridsome-personal-webite/node_modules/gridsome/lib/app/Plugins.js:141:17)
    at async module.exports (/Users/rasulkireev/git/webdev/gridsome-personal-webite/node_modules/gridsome/lib/build.js:41:3)

This is how my gridsome.config.js looks like:

{
      use: 'gridsome-plugin-feed',
      options: {
        contentTypes: ['Post'],
        feedOptions: {
          title: 'Rasul Kireev | Blog Feed',
          description: 'All posts written by Rasul Kireev'
        },
        rss: {
          enabled: true,
          output: '/feed.xml'
        },
        atom: {
          enabled: true,
          output: '/feed.atom'
        },
        json: {
          enabled: true,
          output: '/feed.json'
        },
    }
},

Do you have ideas why this error occurs? Thanks in advance.

mvantol1 commented 3 years ago

I see that your question is open for a while, but when I tried this plugin today, I ran into the same message and was able to fix it.

When I ran the build for the first time, I overlooked part of the configuration that mentions that the date should be a JavaScript Date object. In my blog posts, my dates are strings, so I had to transform them.

Did you try the following already?

nodeToFeedItem: (node) => ({ title: node.title, date: new Date(node.date), content: node.content })

rasulkireev commented 3 years ago

Nice. I decided to try a fork of this lib and it had all the features that I needed. Thanks for the fix though!!