Skip to content

fix: Storyblok Progr. create pages from data #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
require('dotenv').config({
path: `.env.dev`,
});

module.exports = {
siteMetadata: {
siteUrl: "https://demo.raae.codes",
title: "@raae demo starter",
},
plugins: ["gatsby-plugin-gatsby-cloud", "@raae/gatsby-plugin-new-css"],
plugins: [
"gatsby-plugin-gatsby-cloud",
"@raae/gatsby-plugin-new-css",
{
resolve: 'gatsby-source-storyblok',
options: {
accessToken: '2AoGlr4QFWuwXBLbjprVQgtt',
version: 'draft',
}
},
],
};
42 changes: 42 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 0. ↪️ createPages hook ↩️
exports.createPages = async ({ graphql, actions }) => {
// 1. bakingSong = Lilly the Bunny require granny Shark's recipe
const bakingSong = require.resolve('./src/templates/recipe.js')
// 2. Baking supplies = image nodes in Storyblok
const { data } = await graphql(`{
bakingSupplies: allStoryblokEntry(sort: {
fields: created_at,
order: DESC
}) {
nodes {
full_slug
id
}
}
}`)
console.log(data.bakingSupplies.nodes);
// Where are the nodes?

// 3. Loop over the image nodes and for each create a page
// A. 🦊
// B. 🐰
// C. 🐯
// D. 🎩
data.bakingSupplies.nodes.forEach((babySharkBatch, index) => {
actions.createPage({

// A. 🦊 «Ahoy! A path?!» Shouts Fox and embarks. and
path: `/${babySharkBatch.full_slug}`,
// B. 🐰 Bunny sings badly and bakes all the sharks.
component: bakingSong,
// C. 🐯 is the context: { fox: 'is hungry for kitten' } and
context: {
fox: 'is hungry for kitten',
id: babySharkBatch.id,
},

// D. 🎩 They defer the good cookies and maybe get bitten
defer: index + 1 > 1,
});
});
};
Loading