Reactjs Gatsby Source Contentful 4.x-富文本-图像和超链接无法获取

Reactjs Gatsby Source Contentful 4.x-富文本-图像和超链接无法获取,reactjs,gatsby,contentful,Reactjs,Gatsby,Contentful,我有一个盖茨比应用程序,我正在使用内容丰富的文本。contentful最近对现在获取内容的方式做了一些突破性的更改,我完全不知道如何从原始richtext文件中获取链接和图像 下面是到目前为止我所拥有的代码,通过它我可以获取富文本。我看到了标记和s以及所有内容,但当我记录为嵌入式资产块和超链接带回节点的内容时,什么都没有 import React from 'react'; import { graphql, Link } from 'gatsby'; import Img from 'gats

我有一个盖茨比应用程序,我正在使用内容丰富的文本。contentful最近对现在获取内容的方式做了一些突破性的更改,我完全不知道如何从原始richtext文件中获取链接和图像

下面是到目前为止我所拥有的代码,通过它我可以获取富文本。我看到了标记和s以及所有内容,但当我记录为嵌入式资产块和超链接带回节点的内容时,什么都没有

import React from 'react';
import { graphql, Link } from 'gatsby';
import Img from 'gatsby-image';
import { renderRichText } from 'gatsby-source-contentful/rich-text';

import { BLOCKS, MARKS, INLINES } from '@contentful/rich-text-types';

const Bold = ({ children }) => <span className="bold">{children}</span>;
const Text = ({ children }) => <p className="align-center">{children}</p>;

// Setting the rendering options. Same as:
// https://github.com/contentful/rich-text/tree/master/packages/rich-text-react-renderer
const options = {
    renderMark: {
        [MARKS.BOLD]: (text) => <Bold>{text}</Bold>
    },
    renderNode: {
        [INLINES.ENTRY_HYPERLINK]: ({ data }) => <Link to="/">{console.log(data)}</Link>,
        [BLOCKS.PARAGRAPH]: (node, children) => <Text>{children}</Text>,
        [BLOCKS.EMBEDDED_ASSET]: (node) => {
            console.log(node);
        }
    }
};
function privacy({ data }) {
    // console.log(data);

    const description = data.allContentfulBlogPost.nodes[0].bodyRichText;
    return <div>{description && renderRichText(description, options)}</div>;
}

export default privacy;
export const pageQuery = graphql`
    query MyQuery {
        allContentfulBlogPost {
            nodes {
                bodyRichText {
                    raw
                    references {
                        ... on ContentfulAsset {
                            # contentful_id is required to resolve the references
                            contentful_id
                            fluid(maxWidth: 600) {
                                ...GatsbyContentfulFluid_withWebp
                            }
                        }
                    }
                }
            }
        }
    }
`;
从“React”导入React;
从“盖茨比”导入{graphql,Link};
从“盖茨比图像”导入Img;
从“盖茨比源内容/富文本”导入{renderRichText};
从“@contentful/richtexttypes”导入{块、标记、内联线};
const Bold=({children})=>{children};
常量文本=({children})=>

{children}

; //设置渲染选项。等同于: // https://github.com/contentful/rich-text/tree/master/packages/rich-text-react-renderer 常量选项={ 渲染标记:{ [标记.粗体]:(文本)=>{text} }, 渲染节点:{ [INLINES.ENTRY_HYPERLINK]:({data})=>{console.log(data)}, [块.段]:(节点,子节点)=>{children}, [BLOCKS.EMBEDDED_ASSET]:(节点)=>{ console.log(节点); } } }; 函数隐私({data}){ //控制台日志(数据); const description=data.allContentfulBlogPost.nodes[0].bodyRichText; 返回{description&&renderRichText(description,options)}; } 导出默认隐私; export const pageQuery=graphql` 查询我的查询{ allContentfulBlogPost{ 节点{ 正文{ 未经加工的 参考资料{ …关于知足资产{ #解析引用时需要contentful_id 知足的 流体(最大宽度:600){ …GATSBYCONTENTFULL FLUID_与WEBP } } } } } } } `;

有人能帮忙吗?

好的,我发现了问题。我在引用中添加了下面的内容,现在可以看到这些资产了

 ... on ContentfulAsset {
          contentful_id
          __typename
          fixed(width: 1600) {
            width
            height
            src
            srcSet
          }
        }

好的,我发现了问题。我在引用中添加了下面的内容,现在可以看到这些资产了

 ... on ContentfulAsset {
          contentful_id
          __typename
          fixed(width: 1600) {
            width
            height
            src
            srcSet
          }
        }

非常感谢你。我找了几个小时的答案…非常感谢。我花了几个小时寻找答案。。。