Skip to content

Commit

Permalink
Merge pull request layer5io#496 from Tanuj22/Tanuj22/markdown
Browse files Browse the repository at this point in the history
feat: add plugin for markdown and a sample blog
  • Loading branch information
leecalcote authored Jul 20, 2020
2 parents a489714 + 64f35e7 commit 4a627a4
Show file tree
Hide file tree
Showing 13 changed files with 1,350 additions and 373 deletions.
13 changes: 13 additions & 0 deletions layer5-ng/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,26 @@ module.exports = {
offset: -50,
},
},
{
resolve: `gatsby-plugin-mdx`,
options: {
extensions: [`.mdx`, `.md`],
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/posts`,
name: `posts`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
Expand Down
48 changes: 47 additions & 1 deletion layer5-ng/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const { createFilePath } = require(`gatsby-source-filesystem`);
const path = require(`path`)

// You can delete this file if you're not using it
// Replacing '/' would result in empty string which is invalid
Expand All @@ -19,4 +21,48 @@ exports.onCreatePage = ({ page, actions }) => {
deletePage(oldPage)
createPage(page)
}
}
}

exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions;
const blogPostTemplate = path.resolve(
'src/templates/blog-single.js'
);
const res = await graphql(`
{
allMdx {
nodes {
fields {
slug
}
frontmatter {
title
}
}
}
}
`);
const posts = res.data.allMdx.nodes;

posts.forEach(post => {
createPage({
path: post.fields.slug,
component: blogPostTemplate,
context: {
slug: post.fields.slug,
},
})
})
};

exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
if (node.internal.type === `Mdx`) {
const value = createFilePath({ node, getNode });
createNodeField({
name: `slug`,
node,
value,
})
}
};
Loading

0 comments on commit 4a627a4

Please sign in to comment.