操作

在Netlify发布博客

  1. 打开 Netlify 并登录后,点击 New site from Git
  2. Build Command 中填写 hexo g , Publish directory 的目录则填写 public
  3. 顶栏的 Settings 页面下的 Identity,点击 Enable Identity 启用身份管理
  4. 下翻找到 Registration ,将 Open 修改为 Invite Only
  5. 找到 Services 下的 Git Gateway 点击 Enable Git Gateway

博客文件配置

添加 Header
1) 在博客的 Header 中添加一个 JS

<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>

2) 在 source 下创建一个 admin 目录,这个目录的名称可以自行修改为其他名称,但确保后面操作的时候要和此处的名称一致

3) 创建 index.html 文件并键入如下内容

<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
  <meta http-equiv=”X-UA-Compatible” content=”IE=edge,chrome=1″/>
  <meta name="apple-mobile-web-app-status-bar-style" content="white" />
  <title>CMS</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/netlify-cms@2.10.4/dist/cms.css" />
  <script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
</head>
<body>
  <script src="https://cdn.jsdelivr.net/npm/netlify-cms@2.10.4/dist/netlify-cms.js"></script>
</body>
</html>

4) 在 admin 目录下 创建 config.yml 文件并输入如下内容

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

# This line should *not* be indented
publish_mode: editorial_workflow

# This line should *not* be indented
media_folder: "source/images/uploads" # Media files will be stored in the repo under images/uploads
public_folder: "/images/uploads" # The src attribute for uploaded media will begin with /images/uploads

collections:
  - name: "posts" # Used in routes, e.g., /admin/collections/blog
    label: "Post" # Used in the UI
    folder: "source/_posts" # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    slug: "{{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: "Updated Date", name: "updated", widget: "datetime"}
      - {label: "Featured Image", name: "thumbnail", widget: "string"}
      - {label: "abbrlink", name: "abbrlink", widget: "string"}
      - {label: "Tags", name: "tags", widget: "list"}
      - {label: "Categories", name: "categories", widget: "list"}
      - {label: "TOC", name: "toc", widget: "boolean", default: true}
      - {label: "Body", name: "body", widget: "markdown"}

5) 在博客的配置文件 _config.yml 文件中的 skip_render 下添加

skip_render:
  - admin/*

创建 CMS 帐号

  1. Identify 页面点击 Invite user
  2. 输入邮箱,点击确定
  3. 到邮箱收取邮件,点击邮件中的链接
  4. 设置密码
  5. 访问 /admin 目录
  6. 可以对博客上的文章进行编辑了





转载自:Vigorous Pro



Last modification:February 14th, 2020 at 06:54 pm
如果觉得我的文章对你有用,欢迎打赏!