-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): #5 building skeleton to be able to see the pages
- Loading branch information
Showing
2 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); | ||
} | ||
}); | ||
} |