# @content-collections/core 中文文档

规范地址：https://npmcn.com/package/%40content-collections/core/

版本：0\.15\.3
npm 元数据更新时间：2026-09-21T18:14:53.869Z
中文译文更新时间：2026-11-10T16:26:46.325Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40content-collections/core
原文对照：https://npmcn.com/package/%40content-collections/core/?lang=original
项目主页：https://content-collections.dev/
源码仓库：https://github.com/sdorra/content-collections

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：134 kB，5 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：11 个
- peer 依赖：typescript ^5\.0\.2 \|\| ^6\.0\.0 \|\| ^7\.0\.0
- 首次发布：2024-01-15T20:05:59.796Z
- 最新版本发布：2026-09-21T18:14:53.604Z
- 近 30 天下载量：698066（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：37（近 12 个月 10 个）

## 中文简介

内容收集核心

## 安装

```sh
npm install @content-collections/core
```

也可以使用：`pnpm add @content-collections/core`、`yarn add @content-collections/core`、`bun add @content-collections/core`

## README

# 内容集

[![logo: A staple of books](https://github.com/sdorra/content-collections/blob/main/website/assets/logo_96x96.png?raw=true)](https://content-collections.dev/)

将您的内容转换为类型安全数据收集 。 消除人工取取和解析数据的必要性。 只要输入你的内容并开始。 内建验证可确保您的数据的准确性。 在您的数据输入您的应用程序前进行预处理 .

## 特征

-   **美丽的DX**数字 : 内容集旨在提供愉快的用户体验. 它提供了一个无缝开发者的经验,无需重启服务器或刷新浏览器. 内容集在修改内容时会自动更新.
    
-   **类型安全**数字 : 您的内容在构建过程中被解析和验证,保证准确性和货币性. 内容收藏为访问您的内容提供了一个类型安全的 API .
    
-   **简单使用**数字 : 无需再手动获取并解析内容 。 只需导入并开始使用内容收藏. 它提供了一个简单的API,允许您集中精力构建您的应用程序.
    
-   **转变**数字 : 内容收藏允许您在内容输入您的应用程序前进行转换 。 您可以使用它来修改您的内容, 加入两个收藏, 甚至从服务器获取数据 .
    

## 安装

内容集提供各种适配器,能与通俗的网络框架无缝地融合. 安装过程取决于所选适配器:

-   [下一个.js](https://www.content-collections.dev/docs/quickstart/next)
-   [齐克](https://www.content-collections.dev/docs/quickstart/qwik)
-   [Remix (视频)](https://www.content-collections.dev/docs/quickstart/remix-vite)
-   [固态启动](https://www.content-collections.dev/docs/quickstart/solid-start)
-   [斯维尔特基特](https://www.content-collections.dev/docs/quickstart/svelte-kit)
-   [维特](https://www.content-collections.dev/docs/quickstart/vite)

如果您的框架未列出, 您仍可以通过使用 [国 际](https://www.content-collections.dev/docs/quickstart/cli)。如果想要看到框架列出,请打开一张票.

## 使用量

1.  在项目根部创建内容收集.ts文件 :
    
    ```ts
    import { defineCollection, defineConfig } from "@content-collections/core";
    
    const posts = defineCollection({
      name: "posts",
      directory: "src/posts",
      include: "**/*.md",
      schema: (z) => ({
        title: z.string(),
        summary: z.string(),
        content: z.string(),
      }),
    });
    
    export default defineConfig({
      content: [posts],
    });
    ```
    
2.  开始写入内容 `src/posts`数字 :
    
    ```md
    ---
    title: Hello World
    summary: This is my first post
    ---
    
    # Hello World
    
    This is my first post.
    ```
    
3.  在应用程序中使用您的内容 :
    
    ```tsx
    import { allPosts } from "content-collections";
    
    export function Posts() {
      return (
        <ul>
          {allPosts.map((post) => (
            <li key={post._meta.path}>
              <a href={`/posts/${post._meta.path}`}>
                <h3>{post.title}</h3>
                <p>{post.summary}</p>
              </a>
            </li>
          ))}
        </ul>
      );
    }
    ```
    
    请注意,上述例子仅显示了内容集的基本内容,并不涵盖内容转换. 内容集不默认会改变内容如平分或mdx. 但它有包 可以为你做到这一点:
    
    -   [@ 内容收集/ 标记下](https://www.content-collections.dev/docs/samples/markdown)
    -   [@ 内容收藏/ mdx](https://www.content-collections.dev/docs/samples/mdx)
    
    如果您想要看到更多实例并使用实例,请参考 [文档](https://content-collections.dev/docs)。 。 。 .
    

## 发起人

 [![supastarter](https://npmcn.com/package/%40content-collections/core/assets/sponsors/supastarter/light.svg)](https://supastarter.dev/)   [![Cloudogu GmbH](https://npmcn.com/package/%40content-collections/core/assets/sponsors/cloudogu.png)](https://cloudogu.com/)

### [成为提案国](https://github.com/sponsors/sdorra)

## 许可证

内容收集根据 [MIT 许可证](https://npmcn.com/package/%40content-collections/core/LICENSE)。 。 。 .

## 常见问题

### @content-collections/core 是什么？

内容收集核心

### 如何安装 @content-collections/core？

在项目目录运行 npm install @content-collections/core，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：typescript（^5\.0\.2 \|\| ^6\.0\.0 \|\| ^7\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @content-collections/core 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @content-collections/core 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @content-collections/core 可以商用吗？

@content-collections/core 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @content-collections/core 的下载量有多少？

根据 npm 官方下载统计，@content-collections/core 在 2026/10/11 – 2026/11/09 这 30 天内被下载 698,066 次，日均约 23,269 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @content-collections/core 还在维护吗？

最新版本 0\.15\.3 发布于 2026/09/22（1 个月前）；至今共发布 37 个版本，其中过去 12 个月发布了 10 个；首次发布于 2024/01/16。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

