Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
joyliu-q committed Aug 24, 2023
1 parent 35fbac7 commit a44c4c6
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 391 deletions.
38 changes: 10 additions & 28 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const html = require('remark-html')
const { paginate } = require('gatsby-awesome-pagination')

const { postsPerPage } = require('./src/constants/blog.ts')
const MemberTemplate = path.resolve(`./src/templates/Member.tsx`)
const AlumnusTemplate = path.resolve(`./src/templates/Alumnus.tsx`)
const MemberTemplate = path.resolve(`./src/templates/members/Member.tsx`)
const AlumnusTemplate = path.resolve(`./src/templates/members/Alumnus.tsx`)
const ProductTemplate = path.resolve(`src/templates/Product.tsx`)
const TagTemplate = path.resolve(`./src/templates/Tag.tsx`)
const BlogPostTemplate = path.resolve(`./src/templates/BlogPost.tsx`)
Expand Down Expand Up @@ -109,7 +109,8 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
// Retrieve ID's of all team members
const {
data: {
allMembersJson: { edges },
allMembersJson: { edges: memberEdges },
allAlumniJson: { edges: alumniEdges },
},
} = await graphql(`
query {
Expand All @@ -118,44 +119,26 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
node {
id
pennkey
alumnus
}
}
}
}
`)
await edges.map(({ node: { id, pennkey } }) =>
createPage({
path: `/team/${pennkey}`,
component: MemberTemplate,
context: {
// Data passed to context is available in page queries as GraphQL vars
id,
pennkey,
},
}),
)

// Retrieve ID's of all alumni
const {
data: {
allAlumniJson: { edges: alumniEdges },
},
} = await graphql(`
query {
allAlumniJson {
edges {
node {
id
pennkey
alumnus
}
}
}
}
`)
await alumniEdges.map(({ node: { id, pennkey } }) =>
edges = memberEdges.concat(alumniEdges)
await edges.map(({ node: { id, pennkey, alumnus } }) =>
createPage({
path: `/alumni/${pennkey}`,
component: AlumnusTemplate,
path: alumnus ? `/alumni/${pennkey}` : `/team/${pennkey}`,
component: alumnus ? AlumnusTemplate : MemberTemplate,
context: {
// Data passed to context is available in page queries as GraphQL vars
id,
Expand All @@ -164,7 +147,6 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
}),
)


/**
* Create pages for products
*/
Expand Down
318 changes: 0 additions & 318 deletions src/templates/Member.tsx

This file was deleted.

Loading

0 comments on commit a44c4c6

Please sign in to comment.