Add Zod validation layer and AI blog generation

Introduce a schema-first validation layer and an AI blog generation
feature, plus one-command Cloudflare provisioning.

- src/schemas/ holds Zod input schemas for post, content, case,
  settings, AI, and keywords; parseForm() in src/lib/form.ts validates
  FormData and returns per-field errors.
- Migrate all admin POST handlers to parseForm, showing field-level
  errors and only redirecting once validation passes.
- Add blog_keywords table and posts.focus_keyword (migration 0002);
  uniqueSlug() centralised in src/data/content.ts.
- Add src/lib/ai.ts (OpenAI-compatible chat completions + optional
  Tavily research) and /admin/ai for AI settings, keyword queue, and
  draft generation.
- Add scripts/setup.mjs (npm run setup) to provision D1/KV, set
  secrets, and optionally migrate, seed, and deploy.
- Document AI secrets, Workers Builds deploy flow, and new schemas
  across README and AGENTS docs.
This commit is contained in:
2026-09-11 23:49:18 +08:00
parent 5b69bc818a
commit fdee1aabd7
41 changed files with 3240 additions and 296 deletions
+5 -4
View File
@@ -19,7 +19,8 @@
"lucide-react": "^1.44.0",
"marked": "^18.0.12",
"react": "^19.3.0",
"react-dom": "^19.3.0"
"react-dom": "^19.3.0",
"zod": "^4.6.2"
},
"devDependencies": {
"@types/node": "^22.20.2",
@@ -9455,9 +9456,9 @@
}
},
"node_modules/zod": {
"version": "4.6.1",
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.1.tgz",
"integrity": "sha512-341aRWQsve0rvronKNTqZpjmzdbUDlFuzHaI/XLg/Ej82qffDJRRfBTCuv7+9q/rMjB6LSLyEBnW4InJeMtt/Q==",
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.2.tgz",
"integrity": "sha512-lh5RCAGFa1Cm2hjtNwLQhSs/AsqdWnTQaBER9fEwN/88pSh7KOtJavtBx/0VlkN/uFd61SwYmljLMDAsHlvzBQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/colinhacks"