问题描述
我有一个类型为 Content 的字段,我想将其呈现为 html。从 GraphQL 端点,我收到一个 slate.js 结构,如
"contentExtended": {
"document": "{\"object\":\"document\",\"data\":{},\"nodes\":[{\"object\":\"block\",\"type\":\"paragraph\",\"nodes\":[{\"object\":\"text\",\"text\":\"Test extended\",\"marks\":[]}]},{\"object\":\"block\",\"text\":\"\",\"type\":\"cloudinaryImage\",\"data\":{\"_joinIds\":[\"5feb1aad43a7940689283e62\"]},\"type\":\"image\",\"type\":\"caption\",\"marks\":[]}]}]},\"marks\":[]}]}]}"
},
其中 contentExtended 是我的字段的名称。
请注意,该文档还包含对 GraphQL 查询结果中其他位置的 cloudinaryImage 的引用,因此我认为由 Keystone.js 决定如何呈现它。
我想将它呈现为我将在我的博客应用程序中使用的 html 代码,并且尽可能不费吹灰之力。
推荐和正确的做法是什么?
作为参考,我拥有的 keystone graphql 模式;我正在使用 allPosts 查询获取帖子。
https://gist.github.com/Firfi/42c9fd94c738cb463e4d7e7e28de751b
解决方法
Keystone 使用 SlateJS v0.47,它具有与现代 SlateJS 不同的格式。
基本上你是一个人,Keystone 不会帮你渲染它。
以下是我如何进行基本渲染的示例:https://gist.github.com/dimaip/0454b58d360f26c1e6a87310ace61f8c
我不使用 cloudinary,所以不确定您应该如何呈现它,但我想您可以使用图像的 id (5feb1aad43a7940689283e62
) 来构建一个 url?