【发布时间】:2019-06-28 00:09:25
【问题描述】:
我正在尝试为我的 markdown 创建一个接受图像源的自定义组件。我无法通过自定义组件显示图像,因为图像不存在,因为它不存在
我也意识到图像路径是由 GatsbyJS 生成的,我不知道如何在 markdown 中检索图像的路径。
我确实有一个包含一些文本的自定义组件,但我无法为图像做同样的事情。
这是一个带有标题和几个单词的简单降价。
index.md
---
title: ToDoApp
---
Hi this is my todoapp app. Below is a bunch of screens
<imageholder src='./screen1.png'></imageholder>
 <!-- it displays... -->
我创建了一个名为 imageholder 的自定义组件,它在显示图像时包含一些逻辑(在不久的将来......)
ImageHolder.js
import React from "react"
export default class ImageHolder extends React.Component {
render() {
return (
<img src={this.props.src} alt="Logo"/>
)
}
}
project-post.js
const renderAst = new rehypeReact({
createElement: React.createElement,
components: {
"imageholder": ImageHolder
},
}).Compiler
我收到了这个……
【问题讨论】:
标签: javascript reactjs components markdown gatsby