Netlify CMS 尝试

 371 字 [静态站点生成器] #SGG

由于最近迁移博客到 Cloudflare Pages 上了,所以这边放弃了

简单步骤

第一步

static/ 目录下创建 admin/ 后台目录,主要是用来登录站点的

第二步

admin/ 目录下创建 index.html (后台入口文件)和 config.yml (配置文件)

index.html

 1<!DOCTYPE html>
 2<html>
 3  <head>
 4    <meta charset="utf-8" />
 5    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 6    <title>Content Manager</title>
 7    <!-- Include the script that enables Netlify Identity on this page. -->
 8    <script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
 9  </head>
10  <body>
11    <!-- Include the script that builds the page and powers Netlify CMS -->
12    <script src="https://unpkg.com/[email protected]^2.0.0/dist/netlify-cms.js"></script>
13  </body>
14</html>

这里可以参考一下我的 config.yml

 1# 在线后端配置
 2backend:
 3  name: git-gateway
 4  branch: master # 分支用来更新(可选; 默认到 master)
 5
 6publish_mode: editorial_workflow
 7show_preview_links: true
 8search: false
 9
10# 本地配置
11local_backend: true # 本地后端(建议开启,本地编辑会快很多)
12locale: [zh_Hans, en] # 语言
13
14# 媒体资源和内容配置
15media_folder: static/img
16public_folder: /img
17collections:
18  - name: "Post"
19    label: "Post"
20    folder: "content/post"
21    create: true
22    slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
23    editor:
24      preview: true
25    fields:
26      - { label: "Title", name: "title", widget: "string" }
27      - { label: "Publish Date", name: "date", widget: "datetime" }
28      - { label: "Description", name: "description", widget: "string" }
29      - { label: "Body", name: "body", widget: "markdown" }

第三步:运行

在运行之前请保证你的目录应该是这样子的

 1archetypes
 2assets
 3  media
 4    uploads
 5content
 6post
 7  test
 8layouts
 9partials
10static
11  admin
12  images

分别在两个终端中运行

第一个终端

1npx netlify-cms-proxy-server

另外一个终端

1hugo server