This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const postsPerPage = 9 | |
| const postsWithoutFeatured = posts.filter(({ node }) => { | |
| return !node.frontmatter.featured | |
| }) | |
| const numPages = Math.ceil(postsWithoutFeatured.length / postsPerPage) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Array.from({ length: numPages }).forEach((_, i) => { | |
| createPage({ | |
| path: i === 0 ? `/blog` : `/blog/page/${i + 1}`, | |
| component: blogListLayout, | |
| context: { | |
| limit: postsPerPage, | |
| skip: i * postsPerPage, | |
| currentPage: i + 1, | |
| numPages, | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react" | |
| import { graphql, Link } from "gatsby" | |
| const BlogPostList = ({ data, pageContext }) => { | |
| const { allMarkdownRemark } = data | |
| return ( | |
| <> | |
| {allMarkdownRemark.edges.map(({ node }) => { | |
| const imageSource = node.frontmatter.image.childImageSharp.fluid.src |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const blogCategoryLayout = path.resolve(`./src/layouts/blog-category.js`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const categories = [] | |
| posts.forEach((post, index) => { | |
| post.node.frontmatter.category.forEach(cat => categories.push(cat)) | |
| createPage({ | |
| path: post.node.fields.slug, | |
| component: blogLayout, | |
| context: { | |
| slug: post.node.fields.slug, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const countCategories = categories.reduce((prev, curr) => { | |
| prev[curr] = (prev[curr] || 0) + 1 | |
| return prev | |
| }, {}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const kebabCase = require(`lodash.kebabcase`) | |
| const allCategories = Object.keys(countCategories) | |
| allCategories.forEach((cat, i) => { | |
| const link = `/blog/category/${kebabCase(cat)}` | |
| Array.from({ | |
| length: Math.ceil(countCategories[cat] / postsPerPage), | |
| }).forEach((_, i) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react" | |
| import kebabCase from "lodash.kebabcase" | |
| import { graphql, Link } from "gatsby" | |
| const BlogCategory = ({ data, pageContext }) => { | |
| const { allMarkdownRemark } = data | |
| return ( | |
| <> | |
| <h1>Categories:</h1> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| posts.forEach((post, index, arr) => { | |
| post.node.frontmatter.category.forEach(cat => categories.push(cat)) | |
| const prev = arr[index - 1] | |
| const next = arr[index + 1] | |
| createPage({ | |
| path: post.node.fields.slug, | |
| component: blogLayout, | |
| context: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const BlogPost = ({ data, pageContext }) => { | |
| const { markdownRemark } = data | |
| const { prev, next } = pageContext | |
| return ( | |
| <> | |
| ... | |
| {prev && ( | |
| <Link to={prev.node.fields.slug}> |