Skip to content
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

Leaderboard build fix #206

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 21 additions & 20 deletions site/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
* See: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/
*/

const path = require(`path`)
const { createFilePath } = require(`gatsby-source-filesystem`)
const path = require(`path`);
const { createFilePath } = require(`gatsby-source-filesystem`);

// Define the template for blog post
const blogPost = path.resolve(`./src/templates/blog-post.js`)
const blogPost = path.resolve(`./src/templates/blog-post.js`);

/**
* @type {import('gatsby').GatsbyNode['createPages']}
*/
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions
const { createPage } = actions;

// Get all markdown blog posts sorted by date
const result = await graphql(`
Expand All @@ -28,26 +28,27 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
}
}
}
`)
`);

if (result.errors) {
reporter.panicOnBuild(
`There was an error loading your blog posts`,
result.errors
)
return
);
return;
}

const posts = result.data.allMarkdownRemark.nodes
const posts = result.data.allMarkdownRemark.nodes;

// Create blog posts pages
// But only if there's at least one markdown file found at "content/blog" (defined in gatsby-config.js)
// `context` is available in the template as a prop and as a variable in GraphQL

if (posts.length > 0) {
posts.forEach((post, index) => {
const previousPostId = index === 0 ? null : posts[index - 1].id
const nextPostId = index === posts.length - 1 ? null : posts[index + 1].id
const previousPostId = index === 0 ? null : posts[index - 1].id;
const nextPostId =
index === posts.length - 1 ? null : posts[index + 1].id;

createPage({
path: post.fields.slug,
Expand All @@ -57,33 +58,33 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
previousPostId,
nextPostId,
},
})
})
});
});
}
}
};

/**
* @type {import('gatsby').GatsbyNode['onCreateNode']}
*/
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
const { createNodeField } = actions;

if (node.internal.type === `MarkdownRemark`) {
const value = createFilePath({ node, getNode })
const value = createFilePath({ node, getNode });

createNodeField({
name: `slug`,
node,
value,
})
});
}
}
};

/**
* @type {import('gatsby').GatsbyNode['createSchemaCustomization']}
*/
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const { createTypes } = actions;

// Explicitly define the siteMetadata {} object
// This way those will always be defined even if removed from gatsby-config.js
Expand Down Expand Up @@ -121,5 +122,5 @@ exports.createSchemaCustomization = ({ actions }) => {
type Fields {
slug: String
}
`)
}
`);
};