diff --git a/blog/test-entry.md b/blog/2020-03-03-test-entry.md similarity index 85% rename from blog/test-entry.md rename to blog/2020-03-03-test-entry.md index 5d93558..dbb9184 100644 --- a/blog/test-entry.md +++ b/blog/2020-03-03-test-entry.md @@ -4,4 +4,4 @@ date: '1970-01-01T22:45:00-01:00' description: 'testing the log posts' --- -# This is a test +Hello diff --git a/gatsby-node.js b/gatsby-node.js index d82229f..d42daf8 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,11 +1,13 @@ const path = require(`path`) +const { createFilePath } = require(`gatsby-source-filesystem`) exports.createPages = async ({ actions, graphql, reporter }) => { const { createPage } = actions const siteTemplate = path.resolve(`src/templates/siteTemplate.js`) + const blogTemplate = path.resolve(`src/templates/blogTemplate.js`) - const result = await graphql(` + const pages = await graphql(` { allMdx(limit: 1000, filter: { fields: { source: { eq: "pages" } } }) { edges { @@ -20,31 +22,70 @@ exports.createPages = async ({ actions, graphql, reporter }) => { } } `) - // Handle errors - if (result.errors) { - reporter.panicOnBuild(`Error while running GraphQL query.`) + if (pages.errors) { + reporter.panicOnBuild(`Error while running pages GraphQL query.`) return } - result.data.allMdx.edges.forEach(({ node }) => { + const blogEntries = await graphql(` + { + allMdx(limit: 1000, filter: { fields: { source: { eq: "blog" } } }) { + edges { + node { + fields { + slug + } + frontmatter { + title + date + description + } + } + } + } + } + `) + // Handle errors + if (pages.errors) { + reporter.panicOnBuild(`Error while running blog-entry GraphQL query.`) + return + } + + pages.data.allMdx.edges.forEach(({ node }) => { createPage({ path: node.frontmatter.path, component: siteTemplate, context: {}, // additional data can be passed via context }) }) + blogEntries.data.allMdx.edges.forEach(({ node }) => { + console.log(node.fields.slug) + createPage({ + path: node.fields.slug, + component: blogTemplate, + context: { + slug: node.fields.slug, + }, + }) + }) } exports.onCreateNode = ({ node, getNode, actions }) => { const { createNodeField } = actions if (node.internal.type === `Mdx`) { - const value = getNode(node.parent).sourceInstanceName + const source = getNode(node.parent).sourceInstanceName createNodeField({ node, name: `source`, - value, + value: source, + }) + const path = createFilePath({ node, getNode }) + createNodeField({ + node, + name: `slug`, + value: path, }) } } diff --git a/src/components/layout.js b/src/components/layout.js index 1a2010d..add70fe 100644 --- a/src/components/layout.js +++ b/src/components/layout.js @@ -1,7 +1,7 @@ -import React from "react" -import Nav from "../components/nav" -import Footer from "../components/footer" -import layoutStyles from "./layout.module.css" +import React from 'react' +import Nav from '../components/nav' +import Footer from '../components/footer' +import layoutStyles from './layout.module.css' export default ({ path, editLink, children }) => ( <> diff --git a/src/templates/blogTemplate.js b/src/templates/blogTemplate.js new file mode 100644 index 0000000..f7fd9f1 --- /dev/null +++ b/src/templates/blogTemplate.js @@ -0,0 +1,54 @@ +import React, { useEffect } from 'react' +import { graphql } from 'gatsby' +import Layout from '../components/layout' +import { MDXRenderer } from 'gatsby-plugin-mdx' +import { MDXProvider } from '@mdx-js/react' + +const MdLeakH1 = props =>