【问题标题】:Contentful: Why are Embedded Assets in Rich Text represented inconsistently in Content JSON?内容丰富:为什么富文本中的嵌入式资产在内容 JSON 中的表示不一致?
【发布时间】:2019-12-09 21:05:54
【问题描述】:

我目前正在开发一个 Gatsby-Contentful 网站,我有两篇关于 Contentful 的帖子,每篇帖子的富文本字段都包含嵌入式资产。

在一个富文本字段中,此嵌入资产显示如下:

{
"data": {
                      "target": {
                        "sys": {
                          "space": {
                            "sys": {
                              "type": "Link",
                              "linkType": "Space",
                              "id": "aw0p4zkj7lhv"
                            }
                          },
                          "id": "c5N0u9h6AksECP8JZEzOe1D",
                          "type": "Asset",
                          "createdAt": "2019-07-29T11:48:08.826Z",
                          "updatedAt": "2019-07-29T11:48:08.826Z",
                          "environment": {
                            "sys": {
                              "id": "master",
                              "type": "Link",
                              "linkType": "Environment"
                            }
                          },
                          "revision": 1
                        },
                        "fields": {
                          "title": {
                            "en-US": "dummy"
                          },
                          "description": {
                            "en-US": "dummy so api works"
                          },
                          "file": {
                            "en-US": {
                              "url": "//images.ctfassets.net/aw0p4zkj7lhv/5N0u9h6AksECP8JZEzOe1D/af219e63f6e381c7124a6d65a0fe85e0/test.jpg",
                              "details": {
                                "size": 58342,
                                "image": {
                                  "width": 1000,
                                  "height": 666
                                }
                              },
                              "fileName": "test.jpg",
                              "contentType": "image/jpeg"
                            }
                          }
                        }
                      }
                    },
                    "content": [],
                    "nodeType": "embedded-asset-block"
                  }
}

而在另一个帖子的富文本字段中,它丢失了很多数据:

{
"data": {
                      "target": {
                        "sys": {
                          "id": "c5N0u9h6AksECP8JZEzOe1D",
                          "type": "Link",
                          "linkType": "Asset"
                        }
                      }
                    },
                    "content": [],
                    "nodeType": "embedded-asset-block"
                  }
}

当我以完全相同的方式在两个富文本字段中嵌入图像时,为什么会出现这种差异?

【问题讨论】:

  • 重复相同的 RTF ? ID 在两种情况下都是相同的,所以可能不需要重复所有属性 eact time(?) 如果您删除第一个,第二个应该增长 (?)
  • 我遇到了类似的问题。图像数据在检索到的 graphql 数据中可用,但在对富文本使用 documentToReactComponents() 方法时引用的节点中不可用。使用 [BLOCKS.EMBEDDED_ENTRY] 作为 renderNode 选项。你找到解决办法了吗?我很想将条目 id 传递给一个组件,该组件对该资产进行另一个 graphql 查找。

标签: javascript json gatsby contentful


【解决方案1】:

当我遇到这种情况时,我通常必须删除缓存 (root/.cache) 和公共 (root/public) 文件夹并重新启动服务器以从 Contentful 获取正确的数据。

【讨论】:

    【解决方案2】:

    发生这种情况是因为您的缓存文件在重建期间未正确更新。

    只需使用 npm install -g gatsby-cli 安装 Gatsby CLI

    然后gatsby clean

    然后gatsby develop

    【讨论】:

      猜你喜欢
      • 2019-06-02
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2021-11-26
      • 2021-11-14
      相关资源
      最近更新 更多