Contentful CMS 未正确显示数据

发布于 2025-01-09 09:01:41 字数 844 浏览 1 评论 0原文

我将 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,
    },
  };
}

内容数据缺少字段,仅显示 sys 对象您可以在此处查看

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

定格我的天空 2025-01-16 09:01:41

对于将来遇到同样问题的人,这里是解决方案,只需将 include 属性添加到您要获取条目的方法中
点击此处了解更多信息
include 在幕后解析此包。包在这里 contentful-resolve-response

const entry = await client.getEntries(
  { 
    content_type: "page",
    "fields.slug": "home",
    include: 10 
  }
);

For someone in the future who encounters the same, here is the solution just add include property to your method where you are fetching the entries
Read more here
include resolves this package behind the scenes. Package is here contentful-resolve-response

const entry = await client.getEntries(
  { 
    content_type: "page",
    "fields.slug": "home",
    include: 10 
  }
);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文