日期:2026-03-08 问题:后台登录时跳转到 Netlify
Decap CMS(原名 Netlify CMS)在初始化时会检查是否有 Git Gateway 或 Netlify 认证配置。由于项目使用了 Cloudflare Pages 部署,Decap CMS 可能会尝试查找 Netlify Identity 服务,导致跳转到 Netlify。
之前尝试过多种 CMS 配置:
- Sveltia CMS - 需要 OAuth App,但 Cloudflare Workers 对 OAuth 支持有限
- Decap CMS - 默认会检查 Netlify 相关配置
使用 Decap CMS(之前称为 Netlify CMS),配置如下:
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>網站管理後台</title>
</head>
<body>
<script src="https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js"></script>
</body>
</html>backend:
name: github
repo: q17603008535-netizen/jade-website
branch: main
auth_type: implicit
media_folder: public/images
public_folder: /images
locale: zh-Hant
collections:
# 产品管理
- name: products
folder: src/content/products
create: true
slug: "{{slug}}"
fields:
- {name: name, label: 產品名稱, widget: string}
- {name: image, label: 產品圖片, widget: image}
- name: params
label: 產品參數
widget: object
fields:
- {name: weight, label: 重量, widget: string}
- {name: mine, label: 礦區, widget: string}
- {name: skin, label: 皮殼, widget: string}
- {name: water, label: 種水, widget: string}
- {name: size, label: 尺寸, widget: string}
# 联系方式
- name: contact
files:
- file: src/config/contact.json
name: contact
label: 聯繫方式
fields:
- {name: wechat, label: 微信 ID, widget: string}
- {name: line, label: Line ID, widget: string}
# 网站配置
- name: site
files:
- file: src/config/site.json
name: site
label: 網站配置
fields:
- {name: siteName, label: 網站名稱, widget: string}
- {name: youtubeId, label: YouTube ID, widget: string}- auth_type: implicit - 必须添加,否则会跳转到 Netlify
- 不能混用 CMS - 不能同时配置 Sveltia CMS 和 Decap CMS
- GitHub OAuth - 需要在 GitHub 开发者设置中配置 OAuth App
如果遇到类似问题:
- 检查 index.html 中引入的 CMS JS 库
- 检查 config.yml 中的 backend 配置
- 确保 auth_type 设置正确
- 清除浏览器缓存后重试