Skip to content

Commit

Permalink
change section type name
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongao97 committed Jan 24, 2024
1 parent ffb6ba0 commit 82f498e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
7 changes: 6 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ module.exports = {
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
`gatsby-transformer-sharp`,
`gatsby-transformer-json`,
{
resolve: `gatsby-transformer-json`,
options: {
typeName: 'BookSection',
},
},
`gatsby-plugin-postcss`,
`gatsby-plugin-react-helmet`,
],
Expand Down
10 changes: 5 additions & 5 deletions gatsby/create-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = async ({ graphql, actions, reporter }) => {

const result = await graphql(`
query {
allChaptersJson {
allBookSection {
edges {
previous {
id
Expand All @@ -26,11 +26,11 @@ module.exports = async ({ graphql, actions, reporter }) => {
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query');
}

// Create a page for each chapter
const chapters = result.data.allChaptersJson.edges;
// Create a page for each sections
const sections = result.data.allBookSection.edges;

if (chapters.length > 0) {
chapters.forEach(({ previous, node, next }) => {
if (sections.length > 0) {
sections.forEach(({ previous, node, next }) => {
const previousId = previous === null ? null : previous.id;
const nextId = next === null ? null : next.id;

Expand Down
4 changes: 2 additions & 2 deletions gatsby/create-resolvers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Add images field to each ChaptersJson node
module.exports = ({ createResolvers }) => {
// Add images field
const resolvers = {
ChaptersJson: {
BookSection: {
images: {
type: ['File'],
resolve: async (source, args, context, info) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/ChapterNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useStaticQuery, graphql, Link } from 'gatsby';
const ChapterNav = () => {
const data = useStaticQuery(graphql`
query QueryChaptersLink {
allChaptersJson {
allBookSection {
edges {
node {
id
Expand All @@ -19,7 +19,7 @@ const ChapterNav = () => {
return (
<nav className="py-6">
<ul className="space-y-1">
{data.allChaptersJson.edges.map(({ node }) => {
{data.allBookSection.edges.map(({ node }) => {
return (
<li key={node.slug}>
<Link
Expand Down
6 changes: 3 additions & 3 deletions src/layouts/ChapterLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function ChapterLayout({ data }) {

export const query = graphql`
query ChapterById($id: String!, $previousId: String, $nextId: String) {
chapter: chaptersJson(id: { eq: $id }) {
chapter: bookSection(id: { eq: $id }) {
id
slug
title
Expand All @@ -93,11 +93,11 @@ export const query = graphql`
}
}
}
previous: chaptersJson(id: { eq: $previousId }) {
previous: bookSection(id: { eq: $previousId }) {
slug
title
}
next: chaptersJson(id: { eq: $nextId }) {
next: bookSection(id: { eq: $nextId }) {
slug
title
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function IndexPage({ data }) {

<div className="py-8 px-6 mx-auto prose">
<ul>
{data.allChaptersJson.edges.map(({ node }) => {
{data.allBookSection.edges.map(({ node }) => {
return (
<li key={node.id}>
<Link to={`/${node.slug}/`}>{node.title}</Link>
Expand All @@ -28,7 +28,7 @@ export default function IndexPage({ data }) {

export const query = graphql`
query QueryChapters {
allChaptersJson {
allBookSection {
edges {
node {
id
Expand Down

0 comments on commit 82f498e

Please sign in to comment.