@ascorbic/airtable-loader

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

This package provides a Airtable loader for Astro. It allows you to load records from an Airtable base and use them as content in your Astro project.

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. Options

Astro Airtable loader

This package provides a Airtable loader for Astro. It allows you to load records from an Airtable base and use them as content in your Astro project.

Installation

npm install @ascorbic/airtable-loader

Usage

This package requires Astro 4.14.0 or later. You must enable the experimental content layer in Astro unless you are using version 5.0.0-beta or later. You can do this by adding the following to your astro.config.mjs:

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

You will need to create an Airtable personal access token. You can create one here.

You should ensure that this token has access to the base that you want to use, and has the following scopes:

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

You can then use the feed loader in your content collection configuration:

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

You can then use these like any other content collection in Astro. The data is type-safe, and the types are automatically generated based on the schema of the Airtable table.

---
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>

Options

The airtableLoader function takes an object with the following options:

  • base: The ID of the Airtable base you want to load records from.
  • table: The name or ID of the table in the base you want to load records from.
  • token: Your Airtable personal access token. If not provided, it will be read from the AIRTABLE_TOKEN environment variable.
  • queryParams: An optional object with options to pass to the Airtable API. This can be used to filter or limit the records returned. See the Airtable query documentation for more information.

版本与发布记录

@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 是什么?

This package provides a Airtable loader for Astro. It allows you to load records from an Airtable base and use them as content in your Astro project.

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