---
title: Cards 卡片
description: 链接卡片——card()/cards() 网格、GitHub 仓库卡片与 Bilibili 视频链接卡片。
---

`card()` 构建单张卡片；`cards()` 将任意数量卡片包进 Plumest 风格响应式网格。
富信息链接卡片（仓库、视频）请使用下方的 `GitHubCard` / `BilibiliCard`。

## 网格

```ts
cards([
  { title: 'Markdown 创作', description: '用纯 Markdown 写文档。', href: '/guides/example/', icon: 'lucide:file-text' },
  { title: '组件画廊', description: '全部构建器实时展示。', href: '/contribution/components/', icon: 'lucide:zap' },
  { title: '设计令牌', description: '单一事实来源。', href: '/contribution/styles/', icon: 'lucide:palette' },
]);
```

## 单卡片状态

```ts
card({ title: '开始使用', description: '链接到某处的卡片。', href: '/guides/example/', icon: 'lucide:arrow-right' });
card({ title: '纯卡片', description: '无图标、无链接——纯内容块。', children: '<p>额外的 HTML 内容。</p>' });
card({ title: 'Plumest', description: '外链在新标签页打开。', href: 'https://GitHub.com/CelPlume/CelestPlume', external: true, icon: 'lucide:external-link' });
```

## 参数

<PropsTable
  labels={{ prop: '参数', type: '类型', default: '默认值' }}
  type={{
    title: { type: 'string', required: true, description: '卡片标题。' },
    description: { type: 'string', default: "''", description: '说明文字。' },
    href: { type: 'string', default: "''", description: '目标地址——带它时卡片渲染为 <code>&lt;a&gt;</code>。' },
    external: { type: 'boolean', default: 'false', description: '在新标签页打开链接。' },
    icon: { type: 'string', default: "''", description: 'Iconify 图标名（如 <code>lucide:zap</code>）或原始 SVG。' },
    children: { type: 'string', default: "''", description: '说明下方的额外 HTML。' },
  }}
/>

## 注意

- 图标经项目本地 `@iconify-json` 图标集解析——运行时绝不从 Iconify API 在线拉取。
- `cards()` 接受 `CardOptions[]` 或单个预构建 HTML 字符串。

## GitHub 仓库卡片

`GitHubCard` 每次使用渲染一张 GitHub 仓库卡片——整卡为链接，标题显示
`owner/repo`。描述、语言与 star/fork 数在构建期抓取 GitHub API，并在浏览器
中实时刷新。多个仓库重复使用组件即可。

- [CelPlume/CelestPlume](https://github.com/CelPlume/CelestPlume)

- [CelPlume/BookmarkHarbor](https://github.com/CelPlume/BookmarkHarbor)

```astro
---
import GitHubCard from '../../../../../components/kit/GitHubCard.astro';
---

<GitHubCard owner="CelPlume" repo="CelestPlume" />
<GitHubCard owner="CelPlume" repo="BookmarkHarbor" />
```

### GitHub 卡片参数

<PropsTable
  labels={{ prop: '选项', type: '类型', default: '默认值' }}
  type={{
    owner: { type: 'string', required: true, description: '仓库所有者（用户或组织）。' },
    repo: { type: 'string', required: true, description: '仓库名称。' },
    target: { type: 'string', default: "'_blank'", description: '仓库链接的打开方式。' },
    auth: { type: 'string', default: "''", description: '构建期请求使用的 GitHub token。' },
  }}
/>

注意：

- 整卡链接到仓库；标题显示 `owner/repo`。
- 构建期数据来自 GitHub REST API；请求失败时渲染为纯链接卡片。
- star/fork 数与缺失的元数据在浏览器中刷新，并缓存于 `localStorage`
  以遵守 API 限流。
- 构建与运行时都需要能访问 `api.github.com`。

## Bilibili 链接卡片

`BilibiliCard` 把 Bilibili 视频渲染为链接卡片：封面、标题、简介与 UP主。
元数据在构建期经 Bilibili view API 抓取；请求失败时退化为纯链接卡片。

- [Bilibili: BV1DN411r7co](https://www.bilibili.com/video/BV1DN411r7co)

```astro
---
import BilibiliCard from '../../../../../components/kit/BilibiliCard.astro';
---

<BilibiliCard bvid="BV1DN411r7co" />
```

### Bilibili 卡片参数

<PropsTable
  labels={{ prop: '选项', type: '类型', default: '默认值' }}
  type={{
    bvid: { type: 'string', required: true, description: 'Bilibili 视频 BV 号。' },
    target: { type: 'string', default: "'_blank'", description: '视频链接的打开方式。' },
  }}
/>

注意：

- 封面、头像与外链箭头带 `referrerpolicy="no-referrer"`，避免 Bilibili
  图床因 Referer 拒绝服务。
- 非法 `bvid` 会让构建直接报错。
- 可播放嵌入请见[嵌入媒体](/zh/contribution/components/embed-media/)。
