Skip to content

Commit

Permalink
Merge pull request #4 from newrelic/liz/add-markdown-pages
Browse files Browse the repository at this point in the history
Add markdown page generation
  • Loading branch information
zstix authored Apr 21, 2020
2 parents 030465d + a3e8828 commit e23f4ec
Show file tree
Hide file tree
Showing 6 changed files with 978 additions and 85 deletions.
11 changes: 8 additions & 3 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,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`,
],
};
42 changes: 36 additions & 6 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
/**
* 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 result = await graphql(`
{
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] }
limit: 1000
) {
edges {
node {
frontmatter {
path
template
}
}
}
}
}
`);

// 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: path.resolve(`src/templates/${node.frontmatter.template}.js`),
context: {}, // additional data can be passed via context
});
});
};
Loading

0 comments on commit e23f4ec

Please sign in to comment.