Contentful CMS 未正确显示数据
我将 Contentful CMS(社区版)与 Next.js 一起使用,但 Contentful Client 不断消失响应中的随机数据。每次我需要将条目状态更改为“取消发布”,然后再次发布时,问题就解决了。这太令人不安了,因为它禁止该网站显示数据。此外,更新条目和所有链接数据也非常困难。有人面临同样的情况或有解决方案吗?
export async function fetchEntries() {
// const response = await client.getContentType("page");
const entries = await client.getEntries();
if (entries.items) return entries.items;
}
export async function getStaticProps() {
const entries = await fetchEntries();
let data = entries.filter((item) => item.sys.contentType.sys.id === "page" && item.fields.slug === "home");
return {
props: {
data: data.length ? data[0] : null,
},
};
}
I am using Contentful CMS (community edition) with Next.js but Contentful Client keeps on vanishing the random data in response. Every time I need to change the status of entry to Unpublish and then again publishing it solves the issue. This is too disturbing because it prohibits the site to show data. Also, it's very hard to update entries and all linked data. Is anybody facing the same or have any solution?
export async function fetchEntries() {
// const response = await client.getContentType("page");
const entries = await client.getEntries();
if (entries.items) return entries.items;
}
export async function getStaticProps() {
const entries = await fetchEntries();
let data = entries.filter((item) => item.sys.contentType.sys.id === "page" && item.fields.slug === "home");
return {
props: {
data: data.length ? data[0] : null,
},
};
}
Contentful data is missing fields only sys object is shown You can have a look here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于将来遇到同样问题的人,这里是解决方案,只需将
include
属性添加到您要获取条目的方法中点击此处了解更多信息
include
在幕后解析此包。包在这里 contentful-resolve-responseFor someone in the future who encounters the same, here is the solution just add
include
property to your method where you are fetching the entriesRead more here
include
resolves this package behind the scenes. Package is here contentful-resolve-response