【发布时间】:2022-08-04 14:00:05
【问题描述】:
我试图在我的 Gatsby v4 中为我的网站呈现富文本,但我无法找到有关如何呈现数据的任何信息。我已经阅读了有关添加块的信息,但我不知道应该包括什么或如何去做。我真的只需要在富文本中呈现链接、标题和正文。有人可以帮我完成这个吗?
这是我的组件代码 sn-p。到目前为止,数据都在页面中正确地通过查询。我只是想让文字放在上面写着“TEXT GOES HERE\”的地方
import React from \"react\"
import { useStaticQuery, graphql } from \"gatsby\"
import { GatsbyImage } from \"gatsby-plugin-image\"
import {renderRichText} from \"gatsby-source-contentful/rich-text\"
import {BLOCKS, MARKS} from \"@contentful/rich-text-types\"
import * as aboutStyles from \"../styles/about.module.scss\"
const query = graphql`
{
contentfulAbout {
about
bioImage {
title
url
gatsbyImageData(
layout: FULL_WIDTH
placeholder: BLURRED
resizingBehavior: SCALE
width: 1000
)
}
aboutText {
raw
}
}
}
`
const AboutSection = () => {
const data = useStaticQuery(query);
const contentfulAbout = data.contentfulAbout
return (
<div className={aboutStyles.parent}>
<section className={aboutStyles.container}>
<div className={aboutStyles.image}>
<GatsbyImage className={aboutStyles.bioImage} image={contentfulAbout.bioImage.gatsbyImageData} alt={contentfulAbout.bioImage.title} />
</div>
<div className={aboutStyles.text}>
<h2>{contentfulAbout.about}</h2>
<p>TEXT GOES HERE</p>
</div>
</section>
</div>
)
}
标签: reactjs content-management-system gatsby rich-text-editor