Skip to content

Commit

Permalink
Update gatsby-node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
chinomendez authored Nov 26, 2022
1 parent 7457e8f commit 4cb2acc
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 additions & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,83 @@ exports.createPages = ({ actions }) => {
component: require.resolve("./src/components/footer.js"),
})
}



// in gatsby-node.js
exports.createSchemaCustomization = async ({ actions }) => {
// ...
actions.createTypes(`
type HomepageBanner implements Node & HomepageBlock {
id: ID!
blocktype: String
heading: String
text: String
}
`)
// ...
}
// ...
exports.onCreateNode = ({ actions, node, createNodeId, createContentDigest }) => {
}
// ...
switch (node.internal.type) {
case "WpPage":
if (node.slug !== "homepage") return
const {
homepageHero,
homepageCta,
statList,
testimonialList,
productList,
logoList,
featureList,
benefitList,
// add the new custom field group here
homepageBanner,
} = node

const heroID = createNodeId(`${node.id} >>> HomepageHero`)
// create an node id for the field group
const bannerID = createNodeId(`${node.id} >>> HomepageBanner`)
// ...

// create a new node for this field group
actions.createNode({
id: bannerID,
internal: {
type: "HomepageBanner",
contentDigest: createContentDigest(JSON.stringify(homepageBanner)),
},
parent: node.id,
blocktype: "HomepageBanner",
heading: homepageBanner.bannerHeading,
text: homepageBanner.bannerText,
})
// ...
actions.createNode({
...node,
id: createNodeId(`${node.id} >>> Homepage`),
internal: {
type: "Homepage",
contentDigest: node.internal.contentDigest,
},
parent: node.id,
blocktype: "Homepage",
image: node.featuredImageId,
content: [
heroID,
logosID,
// add your banner content in the postion you would like it to appear on the page
bannerID,
productsID,
featuresID,
benefitsID,
statsID,
testimonialsID,
ctaID,
],
})
// ...
}
}

0 comments on commit 4cb2acc

Please sign in to comment.