跳转到内容

主题颜色

颜色来源
种子颜色
色板风格

CMS 快速开始

这一页带你从零到「读出一条自己创建的内容」。

依赖 版本
Node.js 22 或更高
pnpm 10 或更高
数据库 PostgreSQL 16+ 或 SQLite 3.40+
终端窗口
pnpm add @hhl/cms

内容结构写在 cms.config.ts 里,随代码一起进版本库:

import { defineConfig, field } from '@hhl/cms';
export default defineConfig({
collections: {
post: {
fields: {
title: field.string({ required: true }),
slug: field.slug({ from: 'title' }),
body: field.richText(),
publishedAt: field.date(),
},
},
},
});
终端窗口
pnpm cms dev

默认监听 http://localhost:8787。第一次启动会自动建表。

终端窗口
curl -X POST http://localhost:8787/api/collections/post \
-H 'content-type: application/json' \
-d '{"title":"第一篇","body":"你好"}'

然后读取:

终端窗口
curl http://localhost:8787/api/collections/post

能看到刚才那条数据,就说明整条链路是通的。下一步去看 API 参考,把它接到你的前端。