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