This file contains 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 blogListLayout = path.resolve(`./src/layouts/blog-list.js`) |
This file contains 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 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 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 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 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 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 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}> |
This file contains 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
query blogPosts { | |
allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) { | |
edges { | |
node { | |
frontmatter { | |
title | |
category | |
date | |
} | |
html |
This file contains 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
[...new Set(Array.from(document.querySelectorAll("[class]")).flatMap(e => Array.from(e.classList)))] |