@farm.js/contentful

中文文档
0.1.48发布于 2026/11/01MITTypeScriptES Module零依赖

Contentful content source for Farm.js

原始使用文档

@farm.js/contentful

Contentful content source for Farm.js. Feeds Contentful entries into @farm.js/content collections, where they get the same schema validation, transforms, and generated server types as local Markdown.

import { collection, content } from "@farm.js/content";
import { contentfulSource } from "@farm.js/contentful";

content({
  collections: {
    posts: collection({
      source: contentfulSource({
        contentType: "post",
        query: { order: ["-sys.createdAt"] },
        refreshInterval: 30_000, // dev only
      }),
      schema: post,
    }),
  },
});

Set CONTENTFUL_SPACE_ID and CONTENTFUL_ACCESS_TOKEN, or pass an existing client through client. Entry IDs default to a string fields.slug, falling back to sys.id. Pagination past Contentful's 1000-entry page cap is handled internally. For drafts, set host: "preview.contentful.com" with CONTENTFUL_PREVIEW_TOKEN.

Content is a build-time snapshot: entries are fetched while the configuration loads and bundled into production output. Point a Contentful webhook at your platform's deploy hook to rebuild on publish. See the content plugin docs for the shared pipeline and the live-content alternative.

版本与发布记录

@farm.js/contentful 共发布 61 个版本,首次发布于 2026/09/25;过去 12 个月发布了 61 个版本。

版本发布日期距今
0.1.48latest2026/11/012 天前
0.1.472026/10/313 天前
0.1.462026/10/313 天前
0.1.452026/10/313 天前
0.1.442026/10/313 天前
0.1.432026/10/304 天前

其他发布通道:beta → 0.1.3-beta.0。

关于 @farm.js/contentful 的常见问题

@farm.js/contentful 是什么?

内容丰富的Farm.js内容源

如何安装 @farm.js/contentful?

在项目目录运行 npm install @farm.js/contentful,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:contentful(^10.0.0 || ^11.0.0)、@farm.js/content(^0.1.0-beta.46)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@farm.js/contentful 支持 TypeScript 吗?

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

@farm.js/contentful 支持 ESM 还是 CommonJS?

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

@farm.js/contentful 可以商用吗?

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

@farm.js/contentful 还在维护吗?

最新版本 0.1.48 发布于 2026/11/01(2 天前);至今共发布 61 个版本,其中过去 12 个月发布了 61 个;首次发布于 2026/09/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。