不使用静态网站生成器时如何在Netlify CMS中设置media_folder和public_folder?

问题描述

我正在将Netlify CMS连接到没有静态网站生成器的网站。

在我的config.yml中,我有 media_folder:“ / images / uploads” 。目前,我在config.yml中使用 public_folder:“ / images / uploads” ,据我所知,应该将/ images / uploads添加为index.md中图像的路径。

问题是,无论我在public_folder中写什么,图像始终位于images / uploads / imagename.png中,但markdown文件中图像的路径始终为image / imagename.png。

关于我在这里做错什么的任何指导?

config.yml

backend:

    name: git-gateway

    branch: main # Branch to update (optional; defaults to master)

media_folder: "/images/uploads" # Media files will be stored in the repo under images/uploads

public_folder: "/images/uploads"

collections:

    - label: "Pages"

      name: "pages"

      files:

      - file: "_posts/news/index.md"

        label: "News" # Used in the UI

        name: "news" # Used in routes,e.g.,/admin/collections/blog

        description: "News page"

        fields: # The fields for each document,usually in front matter

          - {label: "Template Key",name: "templateKey",widget: "hidden",default: "news-page"}

          - {label: "Title",name: "title",widget: "string"}

          - {label: Description,name: description,widget: string}

          - {label: Intro,name: intro,widget: object,fields: [{label: Blurbs,name: blurbs,widget: list,fields: [{label: "Title",widget: "string"},{label: Body,name: body,widget: markdown},{label: Image,name: image,widget: image},{label: "Publish Date",name: "date",widget: "datetime"}]}]}

index.md

---

title: Aktuellt

description: "Aktuella händelser.. "

intro:

  blurbs:

    - date: 2020-10-15T10:23:49.470Z

      title: Hej

      body: Test

      image: images/newspaper.jpg

---

在前端获取响应

如您所见,fetch返回的地址为image / newspaper.jpg。实际上,它是images / uploads / newspaper.jpg

enter image description here

解决方法

经过漫长的步行,我终于自己解决了。我只需要删除index.md并在CMS管理界面中再次添加内容。

因此,请解决此问题的步骤:

  • 长途跋涉
  • 删除index.md
  • 通过CMS管理界面添加内容。