diff --git a/gatsby-node.js b/gatsby-node.js index 71150bd..c1b57ee 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -33,6 +33,11 @@ exports.createPages = async ({ graphql, actions }) => { fieldValue } } + categoriesGroup: allMarkdownRemark { + group(field: frontmatter___categories) { + fieldValue + } + } } `); @@ -55,4 +60,14 @@ exports.createPages = async ({ graphql, actions }) => { } }); }); + + result.data.categoriesGroup.group.forEach((category) => { + createPage({ + path: `/categories/${category.fieldValue}/`, + component: path.resolve(`./src/templates/category.js`), + context: { + category: category.fieldValue + } + }); + }); }; \ No newline at end of file diff --git a/src/pages/index.js b/src/pages/index.js index 3d5b12e..595fbe7 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -7,6 +7,13 @@ export default function Home({ data }) { const post = data.allMarkdownRemark.edges[0].node; const siteMetadata = data.site.siteMetadata; + var tags = post.frontmatter.tags.map((tag) => { + return (#{tag}); + }); + var categories = post.frontmatter.categories.map((category) => { + return ({category}); + }); + return (
@@ -16,11 +23,11 @@ export default function Home({ data }) { {post.frontmatter.formattedDate}, {post.frontmatter.fromNowDate}
diff --git a/src/templates/category.js b/src/templates/category.js new file mode 100644 index 0000000..25505be --- /dev/null +++ b/src/templates/category.js @@ -0,0 +1,50 @@ +import React from "react"; +import { graphql } from "gatsby"; +import Page from "./page"; + +export default function Category({ data, pageContext }) { + var { category } = pageContext; + var siteMetadata = data.site.siteMetadata; + var totalCount = data.allMarkdownRemark.totalCount; + var postListItems = data.allMarkdownRemark.edges.map(function(edge) { + return ( +
  • {edge.node.frontmatter.title}
  • + ); + }); + + return ( + +

    + All posts categorized under "{category}". +

    +
      + {postListItems} +
    +
    + ) +} + +export const query = graphql` + query($category: String!) { + allMarkdownRemark( + sort: { fields: [frontmatter___date], order: DESC } + filter: { frontmatter: { categories: { in: [$category] } } } + ) + { + totalCount + edges { + node { + fields { + slug + } + frontmatter { + title + } + } + } + } + site { + ...HeaderInfo + } + } +` \ No newline at end of file diff --git a/src/templates/post.js b/src/templates/post.js index 2d4fda3..7b6ee3c 100644 --- a/src/templates/post.js +++ b/src/templates/post.js @@ -11,7 +11,7 @@ export default function Post({ data }) { return (#{tag}); }); var categories = post.frontmatter.categories.map((category) => { - return (#{category}); + return ({category}); }); return ( @@ -37,7 +37,7 @@ export default function Post({ data }) { shortname='fishybusiness' config={ { - url: "https://www.benramey.com" + data.sitePage.path, + url: "https://www.benramey.com" + post.slug, identifier: post.slug, title: post.frontmatter.title, language: 'en_US' diff --git a/src/templates/tag.js b/src/templates/tag.js index 14917b2..1ba0a36 100644 --- a/src/templates/tag.js +++ b/src/templates/tag.js @@ -15,7 +15,7 @@ export default function Tag({ data, pageContext }) { return (

    - All posts tagged with "{tag}"; + All posts tagged with "{tag}".

      {postListItems}