Loving Tina? us on GitHub0.0k

文档

学习

v.Latest
Documentation

你好,世界!

在此页面上

我们希望将硬编码的“Hello world”问候语移入Tina,以便可以通过Tina编辑器访问和编辑,无需触碰代码

在我们能做到这一点之前,我们首先需要定义一个Tina schema,它将控制我们从Tina接收到的数据的“形状”。

创建你的Schema

1. 打开tina/config.ts文件并找到schema字段。它应该看起来像这样:

这是一个开箱即用的示例schema,但我们将构建自己的。
schema: {
collections: [
{
name: "post",
label: "Posts",
path: "content/posts",
fields: [
{
type: "string",
name: "title",
label: "Title",
isTitle: true,
required: true,
},
{
type: "rich-text",
name: "body",
label: "Body",
isBody: true,
},
],
ui: {
// 这是一个演示路由器。你可以移除它以适应你的网站
router: ({ document }) => `/demo/blog/${document._sys.filename}`,
},
},
],
},

2. 用一个包含我们精彩的Hello World消息的单字段基本条目替换schema:

schema: {
collections: [
{
name: "my_first_collection",
label: "My first collection",
path: "content/first",
fields: [
{
type: "string",
name: "title",
label: "Title",
isTitle: true,
required: true,
}
],
// 现在将其注释掉。我们稍后会回到这里!
// ui: {
// // 这是一个演示路由器。你可以移除它以适应你的网站
// router: ({ document }) => `/demo/blog/${document._sys.filename}`,
// },
},
],
},

添加你的内容!

  1. 启动你的应用并访问http://localhost:3000/admin/index.html
注意在左侧,我们现在有一个“我的第一个集合”菜单项。
  1. 点击该菜单项。
  2. 点击“添加文件”按钮
  3. 你可以看到我们在Schema中描述的单个字段——Title字段。将你的精彩标题“Hello World!”添加到其中。
  4. 点击“保存”
如果我们回到代码中,你会看到一个新文件已被创建。查看content/,你会发现一个first文件夹,其中包含我们的新Markdown内容!first文件夹是我们在schema中定义的path字段。我们在“我的第一个集合”中创建的所有内容都将在此目录中创建。
上次编辑: January 7, 2026