运行npm run generate
时,Contentful API通常会失败。我不确定这是由于它们无法处理负载还是由于我的生成脚本导致动态路由无法执行。奇怪的是,直到几天前它都可以正常工作。
生成功能以构建动态路线
generate: {
routes: async function() {
const productModelNumbers = await client.getEntries({
content_type: "products"
})
const accessoryModelNumbers = await client.getEntries({
content_type: "accessories"
})
const categories = await client.getEntries({
content_type: "category"
})
const productRoutes = productModelNumbers.items.map(product => {
return {
route: `products/${product.fields.category.fields.slug}/${product.fields.modelNumber}`,
payload: product
}
})
const accessoryCategories = categories.items.map(category => {
return {
route: `accessories/${category.fields.slug}`,
payload: category
}
})
const accessoryRoutes = accessoryModelNumbers.items.map(accessory => {
return {
route: `accessories/${accessory.fields.category.fields.slug}/${accessory.fields.modelNumber}`,
payload: accessory
}
})
return [...productRoutes, ...accessoryRoutes, ...accessoryCategories]
}
}
任何见解都会受到赞赏