示例
scribe-cms 常见工作流的可复制代码片段。
安装
将 scribe-cms 添加到任意 Node 20+ 项目中。
pnpm add scribe-cms zod better-sqlite3配置
使用 Zod 定义内容类型 —— 包含可翻译字段、结构化字段和关联字段。
import { z } from "zod";
import { defineConfig, defineContentType, field } from "scribe-cms";
const blogSchema = z.object({
title: field.translatable(z.string().min(1)),
description: field.translatable(z.string().min(50)),
author: field.relation("author"),
});
const authorSchema = z.object({
name: field.structural(z.string().min(1)),
});
export default defineConfig({
rootDir: ".",
locales: ["en", "fr"],
types: [
defineContentType({
id: "blog",
path: "/blog/{slug}",
schema: blogSchema,
slugStrategy: "localized",
}),
defineContentType({
id: "author",
contentDir: "authors",
schema: authorSchema,
}),
],
});内容文件
每个文档对应一个 .mdx 文件——文件名即为英文 slug。
---
title: "你好,世界"
description: "这是第一篇文章,用于向世界长篇大论地问好,因为 Schema 要求描述必须达到五十个字符。"
author: jane
publishedAt: "2026-01-15"
---
正文使用 MDX 格式。**Markdown** 和组件都可以正常使用。运行时
使用类型化客户端读取内容——列出、解析并追踪关联关系。
import { createScribe } from "scribe-cms/runtime";
import config from "./scribe.config";
const scribe = createScribe(config);
const posts = scribe.blog.list("fr");
const { document } = scribe.blog.resolve("hello-world", "fr");
const author = scribe.blog.related(document!, "author");CLI
在构建前验证内容,并使用 Gemini 翻译过时的页面。
scribe validate
scribe translate --locale fr
scribe status