From 385e65ec3930bd59a53e329b0d06c31d166827c2 Mon Sep 17 00:00:00 2001 From: ajfisher Date: Sat, 30 Nov 2019 18:12:34 +1100 Subject: [PATCH] feat(v2): #5 building skeleton to be able to see the pages --- site/gatsby-config.js | 8 +++++++ site/gatsby-node.js | 51 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/site/gatsby-config.js b/site/gatsby-config.js index a21c7df..05e0117 100644 --- a/site/gatsby-config.js +++ b/site/gatsby-config.js @@ -27,6 +27,14 @@ module.exports = { icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site. }, }, + `gatsby-transformer-remark`, + { + resolve: `gatsby-source-filesystem`, + options: { + name: `content`, + path: `${__dirname}/src/content`, + }, + }, // this (optional) plugin enables Progressive Web App + Offline functionality // To learn more, visit: https://gatsby.dev/offline // `gatsby-plugin-offline`, diff --git a/site/gatsby-node.js b/site/gatsby-node.js index 2f42665..358024b 100644 --- a/site/gatsby-node.js +++ b/site/gatsby-node.js @@ -1,7 +1,46 @@ -/** - * Implement Gatsby's Node APIs in this file. - * - * See: https://www.gatsbyjs.org/docs/node-apis/ - */ +const path = require(`path`); -// You can delete this file if you're not using it +exports.createPages = async ({ actions, graphql }) => { + const { createPage } = actions + const result = await graphql(` + { + allMarkdownRemark { + edges { + node { + frontmatter { + slug + date(formatString: "YYYY/MM/DD") + layout + } + } + } + } + } + `) + if (result.errors) { + console.error(result.errors) + } + result.data.allMarkdownRemark.edges.forEach(({ node }) => { + console.log(node.frontmatter.slug); + // TODO fix this to use a date form. + // + const context = { + slug: node.frontmatter.slug + }; + + if (node.frontmatter.layout.startsWith('page')) { + createPage({ + path: node.frontmatter.slug, + component: path.resolve(`src/templates/post.js`), + context + }); + } else { + console.log(node.frontmatter.date + '/' + node.frontmatter.slug); + createPage({ + path: node.frontmatter.date + '/' + node.frontmatter.slug, + component: path.resolve(`src/templates/post.js`), + context + }); + } + }); +}