darthmeme / gridsome-plugin-rss

Generate an RSS feed from your Gridsome data store
15 stars 11 forks source link

Cannot use higher order function on array of objects queried from GraphQL to assign categories in feed item options #12

Closed Edmund1645 closed 5 years ago

Edmund1645 commented 5 years ago

I have the categories from my blog posts as an array containing objects which look like this:

"tags":[
 {
  "id": "JavaScript",
  "title": "JavaScript",
  "path": "/tag/java-script"
}
// more category objects here
]

and in the gridsome.config.js file, where the categories field is under feedItemOptions I try to use a .map() higher-order function to loop through node.tags as queried and return an array containing only titles of the tags this time but I get an error saying:

TypeError: Cannot read property 'map' of undefined
    at categories (/home/edmund/projects/projects/my own/theNinjaBlog/gridsome.config.js:90:30)
    at Object.feedItemOptions (/home/edmund/projects/projects/my own/theNinjaBlog/gridsome.config.js:91:13)
    at collectionData.forEach.item (/home/edmund/projects/projects/my own/theNinjaBlog/node_modules/gridsome-plugin-rss/index.js:27:25)
    at Array.forEach (<anonymous>)
    at api.beforeBuild (/home/edmund/projects/projects/my own/theNinjaBlog/node_modules/gridsome-plugin-rss/index.js:26:20)
    at Promise.all.events.(anonymous function).map (/home/edmund/projects/projects/my own/theNinjaBlog/node_modules/gridsome/lib/app/App.js:144:77)
    at Array.map (<anonymous>)
    at App.dispatch (/home/edmund/projects/projects/my own/theNinjaBlog/node_modules/gridsome/lib/app/App.js:143:47)
    at module.exports (/home/edmund/projects/projects/my own/theNinjaBlog/node_modules/gridsome/lib/build.js:25:13)

I have checked outside the config file by reducing the array in a single file component and logging to the console and that seems to work fine.

Edmund1645 commented 5 years ago

It seems that these properties are present on the node object, a few other rss options do not get generated from config like, description, date, and image_url for posts

Edmund1645 commented 5 years ago

I've found a fix, it turns out the other properties are one level deeper, so i had to use node.fields.*

RehanSaeed commented 4 years ago

Do you have a short snippet to add the tags?