Use promise in gatsby-node.
This commit is contained in:
@@ -1,50 +1,49 @@
|
|||||||
const fs = require("fs")
|
const fs = require('fs');
|
||||||
const categories = JSON.parse(fs.readFileSync("src/data/categories.json"))
|
|
||||||
var slugify = require('slugify')
|
const categories = JSON.parse(fs.readFileSync('src/data/categories.json'));
|
||||||
|
const slugify = require('slugify');
|
||||||
|
|
||||||
exports.createPages = async function ({ actions, graphql }) {
|
exports.createPages = async function ({ actions, graphql }) {
|
||||||
const { createPage } = actions
|
const { createPage } = actions;
|
||||||
categories.forEach(async function(category) {
|
await Promise.all(
|
||||||
const data = await graphql(`query categoryBooksQuery($categoryName: String) {
|
categories.map(async (category) => {
|
||||||
allBooksJson(
|
const data = await graphql(
|
||||||
filter: {
|
`
|
||||||
category: {
|
query categoryBooksQuery($categoryName: String) {
|
||||||
eq: $categoryName
|
allBooksJson(
|
||||||
|
filter: { category: { eq: $categoryName } }
|
||||||
|
sort: { fields: [rating], order: DESC }
|
||||||
|
) {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
url
|
||||||
|
rating
|
||||||
|
author
|
||||||
|
year
|
||||||
|
category
|
||||||
|
image_url
|
||||||
|
description
|
||||||
|
amazon_url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort: {
|
|
||||||
fields: [rating]
|
|
||||||
order: DESC
|
|
||||||
}
|
|
||||||
){
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
id
|
|
||||||
title
|
|
||||||
url
|
|
||||||
rating
|
|
||||||
author
|
|
||||||
year
|
|
||||||
category
|
|
||||||
image_url
|
|
||||||
description
|
|
||||||
amazon_url
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
`,
|
||||||
}
|
{ categoryName: category.name },
|
||||||
`,
|
);
|
||||||
{categoryName: category.name})
|
console.log(category.name, data.data);
|
||||||
console.log(category.name, data.data)
|
createPage({
|
||||||
createPage({
|
|
||||||
path: slugify(category.name),
|
path: slugify(category.name),
|
||||||
component: require.resolve("./src/templates/categoryTemplate.js"),
|
component: require.resolve('./src/templates/categoryTemplate.js'),
|
||||||
context: {
|
context: {
|
||||||
categoryName: category.name,
|
categoryName: category.name,
|
||||||
data: data.data,
|
data: data.data,
|
||||||
image: category.emoji,
|
image: category.emoji,
|
||||||
limit: null,
|
limit: null,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
})
|
}),
|
||||||
}
|
);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user