@ascorbic/airtable-loader

中文文档
1.0.5发布于 2024/11/17MITTypeScriptES Module近 30 天下载 1.3万

这个包件为Astro提供了一台气表装载机. 它允许您从一个 Airtable 基地装入记录,并在您的 Astro 计划中将其作为内容.

中文使用文档
文档目录3 节
  1. 安装
  2. 使用量
  3. 选项

Astro 气压装载机

这个包件为Astro提供了一台气表装载机. 它允许您从一个 Airtable 基地装入记录,并在您的 Astro 计划中将其作为内容.

安装

npm install @ascorbic/airtable-loader

使用量

这个包需要Astro 4.14.0或以后. 您必须启用Astro的实验内容层, 除非您正在使用5. 0.0- beta 版本或稍后使用 。 你可以这样做,在你的 astro.config.mjs数字 :

export default defineConfig({
  // ...
  experimental: {
    contentLayer: true,
  },
});

您需要创建 Airtable 个人访问标志 。 您可以创建一个 这里。 。 。 .

您应该确保此标志能够访问您想要使用的基数,并具有以下范围:

  • data.records:read
  • schema.bases:read

然后可以在内容收集配置中使用种子加载器 :

// src/content/config.ts
import { defineCollection } from "astro:content";
import { airtableLoader } from "@ascorbic/airtable-loader";

const launches = defineCollection({
  loader: airtableLoader({
    base: import.meta.env.AIRTABLE_BASE,
    table: "Product Launches",
  }),
});

export const collections = { launches };

然后,您可以像Astro的其他内容收藏一样使用这些内容. 数据是安全的类型,类型会根据"空气表"的"计划"自动生成.

---
import type { GetStaticPaths } from "astro";
import { getCollection, type CollectionEntry } from "astro:content";
import Layout from "../../layouts/Layout.astro";

export const getStaticPaths: GetStaticPaths = async () => {
  const launches = await getCollection("launches");
  return launches.map((launch) => ({
    params: {
      id: launch.id,
    },
    props: { launch },
  }));
};

type Props = { launch: CollectionEntry<"launches"> };

const { launch } = Astro.props;
const { data } = launch;
---

<Layout title={data.firstName}>
  <h1>{data["Launch Name"]}</h1>
  <p>{data["Launch date"]?.toDateString()}</p>
  <p>{data.Description}</p>
</Layout>

选项

这个 airtableLoader 函数取一个对象,其选项如下:

  • base: AirTable 基地的ID 您想要从中装入记录.
  • table:要从底部装入记录的表格名称或标识.
  • token:你的空中个人访问标志。 如果不提供,请从 AIRTABLE_TOKEN 环境变量.
  • queryParams:可选对象,可选择通过Airtable API. 这可以用来过滤或限制返回的记录. 见 空中查询文件 更多信息.

版本与发布记录

@ascorbic/airtable-loader 共发布 8 个版本,首次发布于 2024/08/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.5latest2024/11/172 年前
1.0.42024/10/282 年前
1.0.32024/10/192 年前
1.0.22024/10/182 年前
1.0.12024/09/132 年前
1.0.02024/08/152 年前

关于 @ascorbic/airtable-loader 的常见问题

@ascorbic/airtable-loader 是什么?

这个包件为Astro提供了一台气表装载机. 它允许您从一个 Airtable 基地装入记录,并在您的 Astro 计划中将其作为内容.

如何安装 @ascorbic/airtable-loader?

在项目目录运行 npm install @ascorbic/airtable-loader,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:astro(^4.14.0 || ^5.0.0-beta.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ascorbic/airtable-loader 支持 TypeScript 吗?

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

@ascorbic/airtable-loader 支持 ESM 还是 CommonJS?

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

@ascorbic/airtable-loader 可以商用吗?

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

@ascorbic/airtable-loader 的下载量有多少?

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

@ascorbic/airtable-loader 还在维护吗?

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