我遇到问题的仓库是https://github.com/agenciaglobal/web 这是我的 gatsby-config.js。至少是有关的部分。
{
resolve: `gatsby-source-filesystem`,
options: { path: `${__dirname}/content`, name: `content` },
},
{
resolve: `gatsby-source-filesystem`,
options: { path: `${__dirname}/content/assets`, name: `assets` },
},
{
resolve: "gatsby-plugin-root-import",
options: {
src: path.join(__dirname, "src"),
content: path.join(__dirname, "content"),
pages: path.join(__dirname, "src/pages"),
shared: path.join(__dirname, "src/shared"),
components: path.join(__dirname, "src/components"),
static: path.join(__dirname, "static"),
},
},
`gatsby-plugin-typescript`,
`gatsby-plugin-layout`,
`gatsby-plugin-feed-mdx`,
{
resolve: `gatsby-transformer-sharp`,
},
`gatsby-plugin-sharp`,
`gatsby-remark-images`,
{
resolve: `gatsby-plugin-mdx`,
options: {
extensions: [".mdx", ".md"],
gatsbyRemarkPlugins: [
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 590,
},
},
],
},
},
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-plugin-material-ui`,
options: { stylesProvider: { injectFirst: true } },
},
{
resolve: `gatsby-plugin-netlify-cms`,
options: { modulePath: `${__dirname}/src/cms.js` },
},
{
resolve: "gatsby-plugin-netlify-cache",
options: { cachePublic: true },
},
整件事都在这里 https://github.com/agenciaglobal/web/blob/master/gatsby-config.js 我的网站正在运行!但我无法使图像正常工作
这是我的收藏
media_folder: content/assets
public_folder: ../assets
collections:
- name: news
label: Notícias
folder: content/news
create: true
fields:
- { name: path, label: Path }
- { name: date, label: Data, widget: date }
- { name: "body", label: "Conteúdo do blog post", widget: "markdown" }
- { name: title, label: Título }
- { name: description, label: Descrição }
- name: postType
label: Tipo de post
widget: select
options:
- { label: "Notícia", value: "news" }
- { label: "Artigo", value: "article" }
- name: type
label: Tipo do box de exibição na lista
widget: select
options:
- { label: "Full", value: "FULL" }
- { label: "Half", value: "HALF" }
- { label: "Mirror", value: "MIRROR" }
- { label: "Left", value: "LEFT" }
- { label: "Right", value: "RIGHT" }
- { label: "Quote", value: "QUOTE" }
- name: "image"
label: "Imagem de destaque"
widget: "image"
- label: "Tags"
name: "tags"
widget: "relation"
collection: "tags"
multiple: true
searchFields: ["tag"]
valueField: "tag"
displayFields: ["tag"]
- label: "Autor do post"
name: "author"
widget: "relation"
collection: "team"
searchFields: ["name", "about", "image"]
valueField: "name"
displayFields: ["name"]
然后实际新闻看起来像这样
---
path: posteee
date: 2020-08-13T13:59:40.634Z
title: hey
description: fe
postType: news
type: HALF
image: assets/10-maria-dornelles.jpg
tags:
- yay!!
author: João Paulo Rocha
---
laõoo
![](../assets/1000x550.png)
这是一个工作配置。但是 cms 永远不会写出这样的路径。这里的问题是,当使用 CMS 插入数据时,它将始终使用public_folder
.
因此,如果我使用assets
,它将在图像字段上工作,但在降价正文上失败。如果我使用../assets
它,它将在降价正文上工作,但在图像 frontmatter 字段上失败
如果我尝试,图像字段将始终失败../assets/whatever.png
。所以我认为我唯一的出路是让降价的主体识别assets/image.png
,而不仅仅是../assets/image.png
. 我怎样才能做到这一点?