【问题标题】:Gatsby and NetlifyCMS image when adding image from the CMS从 CMS 添加图像时的 Gatsby 和 NetlifyCMS 图像
【发布时间】:2021-02-27 03:51:00
【问题描述】:

当我将新图片添加到博客文章时,它会尝试在“blog/1_3azrmh3wkwrmepqn0w9bgw-1-.png”中查找图片

但它不存在,我在静态下设置了所有内容

NetlifyCMS 配置

backend:
  name: git-gateway
  branch: master
publish_mode: editorial_workflow
media_folder: '../assets/images'
public_folder: '/assets/images'

collections:
  - name: 'blog'
    label: 'Blog'
    folder: 'packages/common/src/articles'
    create: true
    slug: 'index'
    path: '{{title}}/index'
    editor:
      preview: true
    fields:
      - { label: 'Title', name: 'title', widget: 'string' }
      - { label: 'Publish Date', name: 'date', widget: 'datetime' }
      - { label: 'Description', name: 'description', widget: 'string' }
      - { label: 'Slug', name: 'slug', widget: 'string'}
      - { label: 'Tags', name: 'tags', add_to_top: true, minimize_collapsed: true, widget: 'list', field: {name: tag, label: Tag, widget: string}  }
      - { label: 'Keywords', name: 'keywords', widget: 'list', add_to_top: true, minimize_collapsed: true, field: {name: Keyword, label: keyword, widget: string} }
      - label: 'Image'
        name: 'image'
        widget: 'object'
        fields:
          - label: ImageUrl
            name: ImageUrl
            widget: image
          - label: ImageAlt
            name: ImageAlt
            widget: string

      - { label: 'Body', name: 'body', widget: 'markdown' }

盖茨比配置

`gatsby-plugin-netlify-cms`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `articles`,
        path: `../common/src/articles`
      }
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `static/assets/images`
      }
    },
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `common-images`,
        path: `static/assets/images`
      }
    },

文件

不知道出了什么问题,但它正在将它们上传到错误的文件夹

【问题讨论】:

  • media_folder 应该相对于 repo 的基础,您是否尝试删除 ../
  • 到 repo 或 cofig yaml?

标签: gatsby netlify netlify-cms


【解决方案1】:

用途:

media_folder: static/assets/images
public_folder: /assets/images

media_folder 必须引用/static 文件夹(此外,删除第一个斜杠,因为它不是必需的)

【讨论】:

  • 我认为这不起作用,CMS 中的降价文件显示的图像是这样的![Flutter Stats](screen-shot-2021-02-27-at-9.04.01 -am.png "颤振统计")
  • 应该是/assets no?
  • 是的,它不工作,它一直把文章放在哪里,也许它的 gasby 配置不知道该怎么做
  • 尝试去除media_folder (..)的相对性
  • 在 gasby 配置或 cms yaml 中?
猜你喜欢
  • 1970-01-01
  • 2020-05-06
  • 2015-04-20
  • 2020-10-05
  • 2020-08-08
  • 2021-08-15
  • 2021-07-20
  • 1970-01-01
  • 2023-03-08
相关资源
最近更新 更多