Refactor feed into a component.
This commit is contained in:
@@ -2,18 +2,46 @@ const fs = require("fs")
|
||||
const categories = JSON.parse(fs.readFileSync("src/data/categories.json"))
|
||||
|
||||
function createSlug (categoryName) {
|
||||
const categoryNameLower = categoryName.toLowerCase();
|
||||
return categoryNameLower.replace(" ", "-");
|
||||
categoryName = categoryName.toLowerCase();
|
||||
categoryName = categoryName.replace(/ /g, "-");
|
||||
categoryName = categoryName.replace(/,/g, "");
|
||||
return categoryName;
|
||||
};
|
||||
|
||||
exports.createPages = ({ actions }) => {
|
||||
exports.createPages = async function ({ actions, graphql }) {
|
||||
const { createPage } = actions
|
||||
categories.forEach(category => {
|
||||
categories.forEach(async function(category) {
|
||||
const data = await graphql(`query categoryBooksQuery($categoryName: String) {
|
||||
allBooksJson(
|
||||
filter: {
|
||||
category: {
|
||||
eq: $categoryName
|
||||
}
|
||||
}
|
||||
){
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
title
|
||||
url
|
||||
rating
|
||||
author
|
||||
year
|
||||
category
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{categoryName: category.name})
|
||||
|
||||
createPage({
|
||||
path: createSlug(category.name),
|
||||
component: require.resolve("./src/templates/categoryTemplate.js"),
|
||||
context: {
|
||||
categoryName: category.name
|
||||
categoryName: category.name,
|
||||
data: data,
|
||||
limit: null,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user