@content-collections/core

中文文档
0.15.3发布于 2026/09/22MITTypeScriptES Module近 30 天下载 69.8万

Core of Content Collections

原始使用文档
文档目录6 节
  1. Features
  2. Installation
  3. Usage
  4. Sponsors
  5. Become a sponsor
  6. License

Content Collections

logo: A staple of books

Transform your content into type-safe data collections. Eliminate the need for manual data fetching and parsing. Simply import your content and begin. Built-in validation ensures the accuracy of your data. Preprocess your data before it enters your app.

Features

  • Beautiful DX: Content Collections is designed to provide a pleasurable user experience. It offers a seamless developer experience without the need to restart the server or refresh the browser. Content collections are automatically updated when you make changes to your content.

  • Type-safe: Your content is parsed and validated during the build process, guaranteeing accuracy and currency. Content Collections offers a type-safe API to access your content.

  • Simple to use: No need to manually fetch and parse your content anymore. Just import it and start using Content Collections. It provides a simple API, allowing you to concentrate on building your app.

  • Transformation: Content Collections allows you to transform your content before it enters your app. You can use it to modify your content, join two collections or even fetch data from a server.

Installation

Content Collections offers a variety of adapters that seamlessly integrate with popular web frameworks. The installation process depends on the chosen adapter:

If your framework is not listed, you can still use Content Collections by using the CLI. Please open a ticket if you want to see your framework listed.

Usage

  1. Create a content-collections.ts file at the root of your project:

    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. Start writing content in src/posts:

    ---
    title: Hello World
    summary: This is my first post
    ---
    
    # Hello World
    
    This is my first post.
    
  3. Use your content in your app:

    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>
      );
    }
    

    Please note that the example above shows only the very basics of Content Collections and it does not cover content transformation. Content Collections does not transform content like markdown or mdx by default. But it has packages which can do that for you:

    If you want to see more examples and use cases, please refer to the documentation.

Sponsors

supastarter    Cloudogu GmbH

Become a sponsor

License

Content Collections is licensed under the MIT License.

版本与发布记录

@content-collections/core 共发布 37 个版本,首次发布于 2024/01/16;过去 12 个月发布了 10 个版本。

版本发布日期距今
0.15.3latest2026/09/221 个月前
0.15.22026/06/164 个月前
0.15.12026/05/265 个月前
0.15.02026/04/166 个月前
0.14.32026/03/237 个月前
0.14.22026/03/038 个月前

关于 @content-collections/core 的常见问题

@content-collections/core 是什么?

Core of Content Collections

如何安装 @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 和提交记录判断。