Dar*_*ren 5 javascript reactjs graphql gatsby
CodeSandbox- https: //codesandbox.io/s/jj597mrvmw
我从外部API返回到我的GatsbyJS / ReactJS网站的某些数据有问题。
更具体地说,问题似乎是在GraphQL查询上使用gatsby-image并gatsby-plugin-sharp使用API 处理图像时出现的。...GatsbyImageSharpFluid
从1000幅图像来看,似乎只有1幅是麻烦的,返回了错误
Errors:
icc_transform: no input profile
vips_colourspace: no known route from 'cmyk' to 'srgb'
Run Code Online (Sandbox Code Playgroud)
我可以过滤掉该图像,但担心将来的图像作为API更新可能会导致相同的问题。
我怎么能够
sharp以便可以处理图像吗?要么,filter在处理时返回此错误的图像createRemoteFileNode,或catch (error)或中跳过有问题的图像createRemoteFileNode内gatsby-node.js是
exports.sourceNodes = async ({ actions, store, cache, createNodeId }) => {
const { createNode, createNodeField } = actions;
const { data } = await axios.get(API_URI);
for (const event of data._embedded.events) {
let fileNode;
let output = [];
let filterResults = event.images.filter(e => e.width >= 1900);
output.push(...filterResults);
try {
fileNode = await createRemoteFileNode({
url: output[0].url,
cache,
store,
createNode,
createNodeId,
});
await createNodeField({
node: fileNode,
name: 'EventImage',
value: 'true'
});
await createNodeField({
node: fileNode,
name: 'name',
value: event.name
});
} catch (error) {
console.warn('error creating node', error);
}
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
191 次 |
| 最近记录: |