-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
45 lines (39 loc) · 1.05 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const path = require(`path`);
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions;
const galleryTemplate = path.resolve(`./src/templates/gallery-page.jsx`);
let pages = await graphql(`
{
allMarkdownRemark(sort: { fields: frontmatter___sort, order: ASC }) {
edges {
node {
frontmatter {
title
slug
eventID
category
}
}
}
}
}
`);
// Handle errors
if (pages.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
pages = pages.data.allMarkdownRemark.edges;
pages.forEach(({ node }, index) => {
createPage({
path: node.frontmatter.slug,
component: galleryTemplate,
context: {
eventID: node.frontmatter.eventID,
category: node.frontmatter.category,
prev: index === 0 ? null : pages[index - 1].node,
next: index === pages.length - 1 ? null : pages[index + 1].node,
},
});
});
};