reactjs - Gatsby-remark-images 偶尔会链接图像
问题描述
我有一个像这样的文件结构:
src
- images
- - blog-images
- - - (various png and jpg files)
- pages
- - blog
- - - (various .md files)
我通过模板成功创建了博客页面。我不知道如何使这些图像出现。我已包含 gatsby-remark-images 并由 gatsby-config.js 修改为如下所示:
plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `blogImages`,
path: `${__dirname}/src/images/blog-images`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `blog`,
path: `${__dirname}/src/pages`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/Favicon.png`, // This path is relative to the root of the site.
},
},
`gatsby-plugin-sass`,
{
resolve: `gatsby-plugin-typography`,
options: {
pathToConfigModule: `src/utils/typography`,
}
},
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 1200
}
}
]
}
},
有时,当我将图像从 blog-images 文件夹移动到 images 或 pages/blog 文件夹时,图像会显示出来。但后来我尝试调整它或通过移动它在页面上获得第二张图像,它停止工作。我撤消了破坏图像的操作,但它不会再回来。
解决方案
发帖没多久,我就明白了。
我试图通过[alt](./filename.png)
或引用图像[alt](./blog-images/filename.png)
。我最终相对于帖子引用了它,而不是我的任何以图像为中心的 gatsby-source-filesystem 配置。
起作用的是[alt](../../images/blog-images/filename.png)
推荐阅读
- bash - 如何限制循环,使其仅对每个值循环一次
- javascript - 如何选择并获取两个输入值?
- python - 如何使用 Python 脚本将 PDF 文档转换为 JSON
- pine-script - 交易视图。如何计算一个指标匹配某个标准的次数?
- paypal - Paypal 智能按钮 - 过期字段(yy vs yyyy)
- java - 测试 MongoDB 存储库方法
- javascript - 正在加载的数据会一直加载到渲染之后
- regex - 如何使用 Excel VBA 获取包含在 2 个字符之间的字符串的特定部分?
- python - 与程序保持一致的 Python 数据库
- latex - 如何使用 dot2tex 在边缘标签中获取乳胶?