Make category pages work.
This commit is contained in:
@@ -1,7 +1,20 @@
|
||||
/**
|
||||
* Implement Gatsby's Node APIs in this file.
|
||||
*
|
||||
* See: https://www.gatsbyjs.org/docs/node-apis/
|
||||
*/
|
||||
const fs = require("fs")
|
||||
const categories = JSON.parse(fs.readFileSync("src/data/categories.json"))
|
||||
|
||||
// You can delete this file if you're not using it
|
||||
function createSlug (categoryName) {
|
||||
const categoryNameLower = categoryName.toLowerCase();
|
||||
return categoryNameLower.replace(" ", "-");
|
||||
};
|
||||
|
||||
exports.createPages = ({ actions }) => {
|
||||
const { createPage } = actions
|
||||
categories.forEach(category => {
|
||||
createPage({
|
||||
path: createSlug(category.name),
|
||||
component: require.resolve("./src/templates/categoryTemplate.js"),
|
||||
context: {
|
||||
categoryName: category.name
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user