从Netlify CMS文件夹中抓取数据



我已经成功地将netlify cms后端链接到我的反应前端,但是现在我的主要问题是弄清楚如何显示其文件夹_posts到我的反应前端的所述数据。

MySite
| _posts
| blog
/2020-06-23-my-post.md
| public

配置.yml

backend:
name: git-gateway
branch: master 
media_folder: "public/images" # Media files will be stored in the repo under static/images/uploads
public_folder: "/images"
collections:
- name: "blog" # Used in routes, e.g., /admin/collections/blog
label: "Blog" # Used in the UI
folder: "_posts/blog" # The path to the folder where the documents are stored
create: true # Allow users to create new documents in this collection
slug: "{{year}}-{{month}}-{{day}}-{{slug}}" # Filename template, e.g., YYYY-MM-DD-title.md
fields: # The fields for each document, usually in front matter
- {label: "Layout", name: "layout", widget: "hidden", default: "blog"}
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}
- {label: "Featured Image", name: "thumbnail", widget: "image"}
- {label: "Rating (scale of 1-5)", name: "rating", widget: "number"}
- {label: "Body", name: "body", widget: "markdown"}

假设您已经为博客文章设置了static/admin/config.yml,如下所示


backend:
name: github
repo: ozluy/destan-nakliyat-gatsby
branch: master
media_folder: static/assets
public_folder: /assets
site_url: https://destan-nakliyat.netlify.app
collections:
- name: post
label: Post
folder: post
create: true
fields:
- { name: path, label: Path }
- { name: date, label: Date, widget: datetime }
- { name: title, label: Title }
- { name: body, label: Body, widget: markdown }

使用gatsby-source-filesystem插件,您可以使用设置插件设置,如下所示gatsby-config.js如下所示:

plugins: [
...,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `pages`,
path: `${__dirname}/post/`,
},
},

最后,您可以通过 GraphQL 访问保存的帖子文件,如下所示:

{
allFile {
edges {
node {
extension
dir
modifiedTime
}
}
}
}

相关内容

  • 没有找到相关文章

最新更新