跳过内容

添加或更新插件

This guide explains how to add new Capacitor plugins to the Capgo website or update existing plugin documentation. This is useful for contributors, maintainers, and AI agents helping to maintain the documentation.

When adding a new plugin to the Capgo ecosystem, you need to update several files and locations across the website to ensure the plugin appears correctly in all relevant places:

  1. 插件列表配置 - 将插件元数据添加到主列表
  2. 插件索引页 - 将插件添加到分类的插件列表页
  3. 侧边栏导航 - 将插件添加到文档侧边栏
  4. 插件文档 - 创建概述和入门页
  5. 插件教程 - 创建全面教程

需要更新的关键文件

标题:需要更新的关键文件
文件目的
/src/config/plugins.ts带有元数据的主插件列表
/src/content/docs/docs/plugins/index.mdx带有分类的插件索引页面
/astro.config.mjs侧边栏导航配置
/src/content/docs/docs/plugins/[plugin-name]/插件文档目录
/src/content/plugins-tutorials/en/英文教程文件
  1. 打开 /src/config/plugins.ts 并添加您的插件到 actions 数组:

    // First, import an appropriate Heroicon
    import YourIconName from 'astro-heroicons/mini/IconName.astro'
    // Then add to the actions array
    {
    name: '@capgo/your-plugin-name',
    author: 'github.com/Cap-go',
    description: 'Brief description of what the plugin does',
    href: 'https://github.com/Cap-go/your-plugin-name/',
    title: 'Display Name',
    icon: YourIconName,
    }

    可用图标: 检查 /node_modules/astro-heroicons/mini/ 可用图标。

  2. 添加插件到首页

    标题:添加插件到首页

    打开 /src/content/docs/docs/plugins/index.mdx 并添加您的插件到适当分类:

    <LinkCard
    title="Your Plugin Name"
    description="Brief description of what the plugin does"
    href="/docs/plugins/your-plugin-name/"
    />

    分类:

    • ⭐ 推荐插件
    • 📱 设备和系统插件
    • 🎥 媒体和摄像头插件
    • 🛠️ 工具插件
    • 🤖 AI和高级媒体
    • 📍 位置和后台服务
    • 📞 通信和分析
    • 🔐 安全和系统
    • 📊 Android特定功能
    • 📥 下载和导航
  3. 添加到侧边栏导航

    标题:添加到侧边栏导航

    打开 /astro.config.mjs 并在侧边栏配置中添加您的插件(约在540行):

    {
    label: 'Your Plugin Name',
    items: [
    { label: 'Overview', link: '/docs/plugins/your-plugin-name/' },
    { label: 'Getting started', link: '/docs/plugins/your-plugin-name/getting-started' },
    ],
    collapsed: true,
    }

    插件在侧边栏中按字母顺序列出。

  4. 创建插件文档目录

    标题:创建插件文档目录

    为您的插件文档创建一个新目录:

    终端窗口
    mkdir -p /src/content/docs/docs/plugins/your-plugin-name/
  5. 创建插件概览页面

    标题:创建插件概览页面

    创建 /src/content/docs/docs/plugins/your-plugin-name/index.mdx:

    ---
    title: "@capgo/your-plugin-name"
    description: Brief description of the plugin's purpose
    tableOfContents: false
    next: false
    prev: false
    sidebar:
    order: 1
    label: "Introduction"
    hero:
    tagline: Detailed tagline explaining what the plugin does
    image:
    file: ~public/your-plugin-icon.svg
    actions:
    - text: Get started
    link: /docs/plugins/your-plugin-name/getting-started/
    icon: right-arrow
    variant: primary
    - text: Github
    link: https://github.com/Cap-go/your-plugin-name/
    icon: external
    variant: minimal
    ---
    import { Card, CardGrid } from '@astrojs/starlight/components';
    <CardGrid stagger>
    <Card title="Feature 1" icon="puzzle">
    Description of first key feature
    </Card>
    <Card title="Feature 2" icon="rocket">
    Description of second key feature
    </Card>
    <Card title="Cross-platform" icon="puzzle">
    Works on both iOS and Android 📱
    </Card>
    <Card title="Comprehensive Documentation" icon="open-book">
    Check the [Documentation](/docs/plugins/your-plugin-name/getting-started/) to master the plugin.
    </Card>
    </CardGrid>
  6. 创建 /src/content/docs/docs/plugins/your-plugin-name/getting-started.mdx:

    ---
    title: Getting Started
    description: Learn how to install and use the plugin in your Capacitor app.
    sidebar:
    order: 2
    ---
    import { Steps } from '@astrojs/starlight/components';
    import { PackageManagers } from 'starlight-package-managers'
    <Steps>
    1. **Install the package**
    <PackageManagers pkg="@capgo/your-plugin-name" pkgManagers={['npm', 'pnpm', 'yarn', 'bun']} />
    2. **Sync with native projects**
    <PackageManagers type="exec" pkg="cap" args="sync" pkgManagers={['npm', 'pnpm', 'yarn', 'bun']} />
    </Steps>
    ## Configuration
    ### iOS Configuration
    [iOS-specific setup instructions]
    ### Android Configuration
    [Android-specific setup instructions]
    ## Usage
    [Basic usage examples]
    ## API Reference
    [Detailed API documentation]
    ## Complete Example
    [Full working example]
    ## Best Practices
    [Recommended practices and tips]
    ## Platform Notes
    [Platform-specific notes and limitations]
  7. 创建 /src/content/plugins-tutorials/en/your-plugin-name.md:

    ---
    locale: en
    ---
    # Using @capgo/your-plugin-name Package
    The `@capgo/your-plugin-name` package [brief description]. In this tutorial, we will guide you through the installation, configuration, and usage of this package in your Ionic Capacitor app.
    ## Installation
    [Installation steps]
    ## Configuration
    [Configuration steps for iOS and Android]
    ## API Usage
    [Detailed API usage examples]
    ## Complete Example
    [Full working example]
    ## Best Practices
    [Tips and best practices]
    ## Troubleshooting
    [Common issues and solutions]
    ## Conclusion
    [Summary and links to additional resources]
src/content/docs/docs/plugins/your-plugin-name/
├── index.mdx # Overview page with hero and feature cards
└── getting-started.mdx # Installation and usage guide
src/content/plugins-tutorials/en/
└── your-plugin-name.md # Comprehensive tutorial

对于复杂的插件,您可以添加额外的文档页面:

src/content/docs/docs/plugins/your-plugin-name/
├── index.mdx
├── getting-started.mdx
├── api-reference.mdx # Detailed API documentation
├── examples.mdx # Additional examples
├── troubleshooting.mdx # Troubleshooting guide
└── migrations.mdx # Migration guides
  • 简洁: 描述长度不超过100个字符
  • 明确说明: 描述插件的功能,而不是它是什么
  • 使用动词开头: 以“控制”,“整合”,“启用”等动词开始

好的例子:

  • “Control device flashlight and torch with simple on/off toggle”
  • “Integrate Crisp live chat and customer support into your app”
  • “Enable secure authentication using Face ID and Touch ID”

不好的例子:

  • “A plugin for flash”
  • “This is a Crisp plugin”
  • “Biometric plugin”
  1. 从安装开始:始终以清晰的安装步骤开始
  2. 提供配置:包含平台特定的设置要求
  3. 展示使用示例:提供工作code示例
  4. 包含API参考:记录所有方法和参数
  5. 添加完整示例:展示真实世界的使用模式
  6. 最佳实践列表: 提供最佳使用建议
  7. 文档平台差异: 解释 iOS 与 Android 行为
  8. 解决常见问题: 解决常见问题
  • 使用 TypeScript 为所有 code 示例
  • 在顶部包含导入语句
  • 添加解释关键步骤的注释
  • 显示错误处理
  • 演示基本和高级使用

检查清单

检查清单

在添加新插件时使用此检查清单:

  • 添加插件到 /src/config/plugins.ts
  • 从 Heroicons 中选择了合适的图标
  • 添加插件到 /src/content/docs/docs/plugins/index.mdx 在正确的类别下
  • /astro.config.mjs
  • 创建插件文档目录
  • 创建 index.mdx 概述页面
  • 创建了 getting-started.mdx 指南
  • 创建了教程 /src/content/plugins-tutorials/en/
  • 包含了安装说明
  • 记录了iOS配置
  • 记录了Android配置
  • 提供了使用示例
  • 添加了API参考
  • 包含了完整的工作示例
  • 列出了最佳实践
  • 添加了平台特定说明
  • 测试了所有链接正确工作

图标参考

图标参考

插件中常用图标(来自 astro-heroicons/mini/):

图标用途
BoltIcon闪光,电源,能源
CameraIcon摄像头,照片,视频
ChatBubbleLeftIcon聊天,信息,沟通
FingerPrintIcon生物识别,安全,身份验证
MapPinIcon位置,地理位置,地图
SpeakerWaveIcon音频,声音,音乐
VideoCameraIcon视频,录制,流媒体
CreditCardIcon支付, 购买
PlayCircleIcon媒体播放器, 视频播放器
SignalIcon连接, 网络, 蓝牙
RadioIcon蓝牙, 广播, 无线
ChatBubbleOvalLeftIcon社交媒体, 微信

更新现有插件

更新现有插件

更新现有插件时:

  1. 更新版本号 在文档中
  2. 添加迁移指南 如果存在破坏性更改
  3. 更新 API 参考 使用新方法
  4. 添加新示例 为新功能
  5. 更新平台要求 如果发生变化
  6. 根据新功能修订最佳实践 根据新功能修订最佳实践
  7. 保持教程 保持最新的 API

语言路径

语言路径

在英语中编写和审阅插件文档。 本地化路径由站点元数据生成,并在边缘由翻译工人进行翻译。

添加或更新插件文档后:

  1. 在本地构建站点:

    终端窗口
    bun run build
  2. 检查错误:

    • 验证所有链接正常工作
    • 确保图像正确加载
    • 确认code示例有效
    • 测试导航功能
  3. 预览网站:

    终端窗口
    bun run dev
  4. 确认插件已显示:

    • 检查插件列表页面
    • 确认侧边栏导航
    • 测试所有文档页面
    • 确认教程页面正常

如果您需要帮助添加或更新插件文档:

为了参考,检查这些文档齐全的插件:

  • 更新器: /src/content/docs/docs/plugins/updater/ (复杂插件,多页)
  • 闪烁: /src/content/docs/docs/plugins/flash/ (简单插件,好用的起始示例)
  • 社交登录: /src/content/docs/docs/plugins/social-login/ (插件及其子页面)

将插件添加到Capgo文档中涉及:

  1. 在主配置中添加元数据
  2. 将插件添加到分类索引页面
  3. 配置侧边栏导航
  4. 创建全面文档页面
  5. 编写详细教程
  6. 在本地测试所有更改

通过遵循本指南,您确保插件始终以一致的方式文档化,并且易于用户发现。