Skip to content

Commit

Permalink
feat: Add markdown page generation
Browse files Browse the repository at this point in the history
  • Loading branch information
LizBaker committed Apr 20, 2020
1 parent c38a56d commit 98d6aa6
Show file tree
Hide file tree
Showing 6 changed files with 830 additions and 10 deletions.
13 changes: 9 additions & 4 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ module.exports = {
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `markdown-pages`,
path: `${__dirname}/src/markdown-pages`,
},
},
`gatsby-transformer-remark`,
],
}
};
43 changes: 37 additions & 6 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
/**
* 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, reporter }) => {
const { createPage } = actions;

const blogPostTemplate = path.resolve(`src/templates/example-template.js`);

const result = await graphql(`
{
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] }
limit: 1000
) {
edges {
node {
frontmatter {
path
}
}
}
}
}
`);

// Handle errors
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}

result.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path: node.frontmatter.path,
component: blogPostTemplate,
context: {}, // additional data can be passed via context
});
});
};
Loading

0 comments on commit 98d6aa6

Please sign in to comment.