hugo配置netlify cms

发布日期:

netlify cms可以为hugo、jekyll等生成的静态站点添加一个后台,可以在线编辑文章上传图片等

在static下新建admin文件夹,新建两个文件

index.html

<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Content Manager</title>
  <script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
</head>
<body>
  <!-- Include the script that builds the page and powers Netlify CMS -->
  <script src="https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js"></script>
  <script>
    if (window.netlifyIdentity) {
      window.netlifyIdentity.on("init", user => {
        if (!user) {
          window.netlifyIdentity.on("login", () => {
            document.location.href = "/admin/";
          });
        }
      });
    }
  </script>
</body>
</html>

config.yml

backend:
  name: git-gateway
  branch: master # Branch to update (optional; defaults to master)

media_folder: static/img
public_folder: /img

collections:
  - name: 'blog'
    label: 'Blog'
    folder: 'content/blog'
    create: true
    slug: '{{slug}}'
    editor:
      preview: false
    fields:
      - { label: '标题', name: 'title', widget: 'string' }
      - { label: '发布日期', name: 'date', widget: 'datetime' }
      - { label: '描述', name: 'description', widget: 'text' }
      - { label: "特色图片", name: "featured_image", widget: "image" }
      - { label: '分类', name: 'category', widget: 'string', default: "碎碎念" }
      - { label: '内容', name: 'body', widget: 'markdown' }

然后在netlify里站点的Identity处设置

Go to Settings > Identity, and select Enable Identity service.

Under Registration preferences, select Invite only.

If you’d like to allow one-click login with services like Google and GitHub, check the boxes next to the services you’d like to use, under External providers.

Scroll down to Services > Git Gateway, and click Enable Git Gateway. This authenticates with your Git host and generates an API access token. In this case, we’re leaving the Roles field blank, which means any logged in user may access the CMS. For information on changing this, check the Netlify Identity documentation.

懒得翻译了,设置这几处应该就能用了,后台直接用github登录!

参考

Add to Your Site | Netlify CMS | Open-Source Content Management System

Hugo | Netlify CMS | Open-Source Content Management System

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注