+ +
diff --git a/gatsby/create-pages.js b/gatsby/create-pages.js
index 6d9025c..3cd2ae6 100644
--- a/gatsby/create-pages.js
+++ b/gatsby/create-pages.js
@@ -7,10 +7,16 @@ module.exports = async ({ graphql, actions, reporter }) => {
query {
allChaptersJson {
edges {
+ previous {
+ id
+ }
node {
slug
id
}
+ next {
+ id
+ }
}
}
}
@@ -21,15 +27,22 @@ module.exports = async ({ graphql, actions, reporter }) => {
}
// Create a page for each chapter
- const pages = result.data.allChaptersJson.edges;
+ const chapters = result.data.allChaptersJson.edges;
- pages.forEach(({ node }) => {
- createPage({
- path: `/${node.slug}/`,
- component: path.resolve(`./src/layouts/ChapterLayout.js`),
- context: {
- id: node.id,
- },
+ if (chapters.length > 0) {
+ chapters.forEach(({ previous, node, next }) => {
+ const previousId = previous === null ? null : previous.id;
+ const nextId = next === null ? null : next.id;
+
+ createPage({
+ path: `/${node.slug}/`,
+ component: path.resolve(`./src/layouts/ChapterLayout.js`),
+ context: {
+ id: node.id,
+ previousId,
+ nextId,
+ },
+ });
});
- });
+ }
};
diff --git a/src/components/PrevNextButtons.js b/src/components/PrevNextButtons.js
new file mode 100644
index 0000000..aa6ccf0
--- /dev/null
+++ b/src/components/PrevNextButtons.js
@@ -0,0 +1,31 @@
+import React from 'react';
+import { Link } from 'gatsby';
+
+const PrevNextButtons = ({ previous, next }) => {
+ return (
+ Previous Chapter Next Chapter