我正在 Gatsby.js 中开发一个网站,其中包含一个博客并用于帖子布局,我正在使用由帖子作者设置的背景图像对这个标题进行编码。我仍处于设计阶段,放置元素,空白文本等。
我已经使用 BackgroundImage、graphQL 和 StaticQuery 制作了这个组件,并且在它的代码中,如果我用“post_8.jpg”文本缩小对来自 gatsby-source-filesystem 的图像的搜索范围,它应该可以正常工作。
import React from 'react'
import { graphql, StaticQuery } from 'gatsby'
import BackgroundImage from 'gatsby-background-image'
import TextScramble from './TextScramble'
const BackgroundDiv = ({ className, children }) => (
<StaticQuery
query={graphql`
query($post: String! ) {
file(relativePath: {eq: "post_8.jpg"}) {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
`
}
render={data => {
const imageData = data.file.childImageSharp.fluid
return (
<BackgroundImage
Tag="div"
className={className}
fluid={imageData}
>
<h1 className="bg-white shaddow shadow-md py-1 px-4 w-auto …Run Code Online (Sandbox Code Playgroud)