You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create a page for each of these categories and tags. For example, if a user clicks on Photoshop, they should be taken to a page tags/photoshop and all posts containing that tag should be listed out.
Fortunately, I was able to find this guide to help me do this. However, the guide is not for Contentful data so I'm having a bit of trouble on how to do this. I have created the tagsTemplate.jsx and but I'm stuck at creating the actual pages.
My gatsby-node.js file looks like this:
constpath=require(`path`)const_=require('lodash');exports.createSchemaCustomization=({ actions })=>{const{ createTypes }=actionsconsttypeDefs=` type contentfulPortfolioDescriptionTextNode implements Node { description: String major: String author: String tools: [String] files: [ContentfulAsset] contact: String } type ContentfulPortfolio implements Node { description: contentfulPortfolioDescriptionTextNode gallery: [ContentfulAsset] id: ID! name: String! related: [ContentfulPortfolio] slug: String! major: String! files: [ContentfulAsset] author: String! tools: [String]! year: String! thumbnail: ContentfulAsset url: String contact: String } `createTypes(typeDefs)}exports.createPages=({ graphql, actions })=>{const{ createPage }=actionsreturnnewPromise((resolve,reject)=>{graphql(` { portfolio: allContentfulPortfolio { nodes { slug tools } } } `).then(({ errors, data })=>{if(errors){reject(errors)}if(data&&data.portfolio){constcomponent=path.resolve("./src/templates/portfolio-item.jsx")data.portfolio.nodes.map(({ slug })=>{createPage({path: `/${slug}`,
component,context: { slug },})})}consttools=data.portfolio.nodes.tools;consttagTemplate=path.resolve(`src/templates/tagsTemplate.js`);lettags=[];// Iterate through each post, putting all found tags into `tags`tags=tags.concat(tools);// Eliminate duplicate tagstags=_.uniq(tags);// Make tag pagestags.forEach(tag=>{createPage({path: `/tags/${_.kebabCase(tag)}/`,component: tagTemplate,context: {
tag,},});});resolve()})})}
When I visit the page for one of the tags I know exists (like photoshop), I get a 404. What am I doing wrong and how can I fix it?
The text was updated successfully, but these errors were encountered:
Each of my posts on Contentful has some associated categories with it. For example, one post might contain:
On the website:
I am trying to create a page for each of these categories and tags. For example, if a user clicks on
Photoshop
, they should be taken to a pagetags/photoshop
and all posts containing that tag should be listed out.Fortunately, I was able to find this guide to help me do this. However, the guide is not for Contentful data so I'm having a bit of trouble on how to do this. I have created the
tagsTemplate.jsx
and but I'm stuck at creating the actual pages.My
gatsby-node.js
file looks like this:When I visit the page for one of the tags I know exists (like
photoshop
), I get a 404. What am I doing wrong and how can I fix it?The text was updated successfully, but these errors were encountered: