gitlab-wiki
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWiki Skill
Wiki技能
Wiki page management for GitLab using raw endpoint calls.
glab api使用原始端点调用进行GitLab Wiki页面管理。
glab apiQuick Reference
快速参考
| Operation | Command Pattern | Risk |
|---|---|---|
| List pages | | - |
| Get page | | - |
| Create page | | ⚠️ |
| Update page | | ⚠️ |
| Delete page | | ⚠️⚠️ |
| Upload attachment | | ⚠️ |
Risk Legend: - Safe | ⚠️ Caution | ⚠️⚠️ Warning | ⚠️⚠️⚠️ Danger
| 操作 | 命令模板 | 风险 |
|---|---|---|
| 列出页面 | | - |
| 获取页面 | | - |
| 创建页面 | | ⚠️ |
| 更新页面 | | ⚠️ |
| 删除页面 | | ⚠️⚠️ |
| 上传附件 | | ⚠️ |
风险说明: - 安全 | ⚠️ 注意 | ⚠️⚠️ 警告 | ⚠️⚠️⚠️ 危险
When to Use This Skill
何时使用此技能
ALWAYS use when:
- User mentions "wiki", "wiki page", "documentation page"
- User wants to create/edit project documentation in GitLab
- User mentions wiki slugs or wiki content
- User wants to upload images to wiki
NEVER use when:
- User wants README files (use gitlab-file)
- User wants to search wiki content (use gitlab-search with scope)
wiki_blobs - User wants external documentation (not GitLab wiki)
务必在以下场景使用:
- 用户提及"wiki"、"wiki页面"、"文档页面"
- 用户想要在GitLab中创建/编辑项目文档
- 用户提及wiki slug或wiki内容
- 用户想要向wiki上传图片
请勿在以下场景使用:
- 用户想要操作README文件(使用gitlab-file技能)
- 用户想要搜索wiki内容(使用gitlab-search并指定范围)
wiki_blobs - 用户想要操作外部文档(非GitLab Wiki)
API Prerequisites
API前置条件
Required Token Scopes:
apiPermissions:
- Read wiki: Reporter+ (for private repos)
- Write wiki: Developer+ (or based on project settings)
Note: Wiki must be enabled for the project.
所需令牌权限:
api权限要求:
- 读取Wiki:Reporter及以上权限(私有仓库)
- 写入Wiki:Developer及以上权限(或根据项目设置)
注意: 项目必须已启用Wiki功能。
Available Commands
可用命令
List Wiki Pages
列出Wiki页面
bash
undefinedbash
undefinedList all wiki pages
列出所有Wiki页面
glab api projects/123/wikis --method GET
glab api projects/123/wikis --method GET
With pagination
分页列出
glab api projects/123/wikis --paginate
glab api projects/123/wikis --paginate
Using project path
使用项目路径
glab api "projects/$(echo 'mygroup/myproject' | jq -Rr @uri)/wikis"
undefinedglab api "projects/$(echo 'mygroup/myproject' | jq -Rr @uri)/wikis"
undefinedGet Wiki Page
获取Wiki页面
bash
undefinedbash
undefinedGet page by slug
通过slug获取页面
glab api projects/123/wikis/home --method GET
glab api projects/123/wikis/home --method GET
Get page with spaces in slug (URL-encode)
获取标题含空格的页面(需URL编码)
glab api "projects/123/wikis/$(echo 'Getting Started' | jq -Rr @uri)" --method GET
glab api "projects/123/wikis/$(echo 'Getting Started' | jq -Rr @uri)" --method GET
Get nested page
获取嵌套页面
glab api "projects/123/wikis/$(echo 'docs/installation' | jq -Rr @uri)" --method GET
glab api "projects/123/wikis/$(echo 'docs/installation' | jq -Rr @uri)" --method GET
Get page with specific version
获取指定版本的页面
glab api "projects/123/wikis/home?version=abc123" --method GET
glab api "projects/123/wikis/home?version=abc123" --method GET
Render HTML
渲染为HTML
glab api "projects/123/wikis/home?render_html=true" --method GET
undefinedglab api "projects/123/wikis/home?render_html=true" --method GET
undefinedCreate Wiki Page
创建Wiki页面
bash
undefinedbash
undefinedCreate simple page
创建简单页面
glab api projects/123/wikis --method POST
-f title="Getting Started"
-f content="# Getting Started\n\nWelcome to the project!"
-f title="Getting Started"
-f content="# Getting Started\n\nWelcome to the project!"
glab api projects/123/wikis --method POST
-f title="Getting Started"
-f content="# Getting Started\n\nWelcome to the project!"
-f title="Getting Started"
-f content="# Getting Started\n\nWelcome to the project!"
Create with Markdown format
创建Markdown格式页面
glab api projects/123/wikis --method POST
-f title="Installation Guide"
-f content="# Installation\n\n## Prerequisites\n\n- Node.js 18+\n- npm"
-f format="markdown"
-f title="Installation Guide"
-f content="# Installation\n\n## Prerequisites\n\n- Node.js 18+\n- npm"
-f format="markdown"
glab api projects/123/wikis --method POST
-f title="Installation Guide"
-f content="# Installation\n\n## Prerequisites\n\n- Node.js 18+\n- npm"
-f format="markdown"
-f title="Installation Guide"
-f content="# Installation\n\n## Prerequisites\n\n- Node.js 18+\n- npm"
-f format="markdown"
Create with custom slug
创建自定义slug的页面
glab api projects/123/wikis --method POST
-f title="API Reference"
-f slug="api-docs"
-f content="# API Documentation\n\nEndpoints..."
-f title="API Reference"
-f slug="api-docs"
-f content="# API Documentation\n\nEndpoints..."
glab api projects/123/wikis --method POST
-f title="API Reference"
-f slug="api-docs"
-f content="# API Documentation\n\nEndpoints..."
-f title="API Reference"
-f slug="api-docs"
-f content="# API Documentation\n\nEndpoints..."
Create nested page (using directory in slug)
创建嵌套页面(在slug中使用目录结构)
glab api projects/123/wikis --method POST
-f title="Database Setup"
-f slug="guides/database-setup"
-f content="# Database Setup\n\nConfiguration steps..."
-f title="Database Setup"
-f slug="guides/database-setup"
-f content="# Database Setup\n\nConfiguration steps..."
undefinedglab api projects/123/wikis --method POST
-f title="Database Setup"
-f slug="guides/database-setup"
-f content="# Database Setup\n\nConfiguration steps..."
-f title="Database Setup"
-f slug="guides/database-setup"
-f content="# Database Setup\n\nConfiguration steps..."
undefinedUpdate Wiki Page
更新Wiki页面
bash
undefinedbash
undefinedUpdate content
更新内容
glab api "projects/123/wikis/$(echo 'Getting Started' | jq -Rr @uri)" --method PUT
-f content="# Getting Started\n\n## Updated content\n\nNew information..."
-f content="# Getting Started\n\n## Updated content\n\nNew information..."
glab api "projects/123/wikis/$(echo 'Getting Started' | jq -Rr @uri)" --method PUT
-f content="# Getting Started\n\n## Updated content\n\nNew information..."
-f content="# Getting Started\n\n## Updated content\n\nNew information..."
Update title and content
更新标题和内容
glab api projects/123/wikis/home --method PUT
-f title="Home Page"
-f content="# Welcome\n\nUpdated home page content."
-f title="Home Page"
-f content="# Welcome\n\nUpdated home page content."
glab api projects/123/wikis/home --method PUT
-f title="Home Page"
-f content="# Welcome\n\nUpdated home page content."
-f title="Home Page"
-f content="# Welcome\n\nUpdated home page content."
Change format (markdown, rdoc, asciidoc)
更改格式(markdown、rdoc、asciidoc)
glab api projects/123/wikis/readme --method PUT
-f format="asciidoc"
-f content="= README\n\nAsciidoc content here."
-f format="asciidoc"
-f content="= README\n\nAsciidoc content here."
undefinedglab api projects/123/wikis/readme --method PUT
-f format="asciidoc"
-f content="= README\n\nAsciidoc content here."
-f format="asciidoc"
-f content="= README\n\nAsciidoc content here."
undefinedDelete Wiki Page
删除Wiki页面
bash
undefinedbash
undefinedDelete page
删除页面
glab api projects/123/wikis/old-page --method DELETE
glab api projects/123/wikis/old-page --method DELETE
Delete nested page (URL-encode)
删除嵌套页面(需URL编码)
glab api "projects/123/wikis/$(echo 'drafts/temp-page' | jq -Rr @uri)" --method DELETE
undefinedglab api "projects/123/wikis/$(echo 'drafts/temp-page' | jq -Rr @uri)" --method DELETE
undefinedUpload Attachment
上传附件
bash
undefinedbash
undefinedUpload image
上传图片
glab api projects/123/wikis/attachments --method POST
-F "file=@screenshot.png"
-F "file=@screenshot.png"
glab api projects/123/wikis/attachments --method POST
-F "file=@screenshot.png"
-F "file=@screenshot.png"
The response contains the markdown link to use
响应中包含可使用的Markdown链接
{"file_name":"screenshot.png","file_path":"uploads/...","branch":"master","link":{"url":"...","markdown":"
"}}
{"file_name":"screenshot.png","file_path":"uploads/...","branch":"master","link":{"url":"...","markdown":"
"}}
undefinedundefinedWiki Page Options
Wiki页面选项
| Option | Type | Description |
|---|---|---|
| string | Page title (required for create) |
| string | Page URL slug (auto-generated from title if not provided) |
| string | Page content |
| string | Content format: |
| 选项 | 类型 | 描述 |
|---|---|---|
| 字符串 | 页面标题(创建时必填) |
| 字符串 | 页面URL别名(若未提供则自动从标题生成) |
| 字符串 | 页面内容 |
| 字符串 | 内容格式: |
Format Support
格式支持
| Format | Extension | Description |
|---|---|---|
| | GitHub-flavored Markdown |
| | Ruby documentation format |
| | AsciiDoc format |
| | Org mode format |
| 格式 | 扩展名 | 描述 |
|---|---|---|
| | GitHub风格Markdown |
| | Ruby文档格式 |
| | AsciiDoc格式 |
| | Org模式格式 |
Common Workflows
常见工作流
Workflow 1: Create Documentation Structure
工作流1:创建文档结构
bash
project_id=123bash
project_id=123Create home page
创建首页
glab api projects/$project_id/wikis --method POST
-f title="Home"
-f content="# Project Wiki\n\n- Getting Started\n- API Reference\n- FAQ"
-f title="Home"
-f content="# Project Wiki\n\n- Getting Started\n- API Reference\n- FAQ"
glab api projects/$project_id/wikis --method POST
-f title="Home"
-f content="# Project Wiki\n\n- Getting Started\n- API Reference\n- FAQ"
-f title="Home"
-f content="# Project Wiki\n\n- Getting Started\n- API Reference\n- FAQ"
Create getting started guide
创建入门指南
glab api projects/$project_id/wikis --method POST
-f title="Getting Started"
-f content="# Getting Started\n\n## Installation\n\n```bash\nnpm install\n```"
-f title="Getting Started"
-f content="# Getting Started\n\n## Installation\n\n```bash\nnpm install\n```"
glab api projects/$project_id/wikis --method POST
-f title="Getting Started"
-f content="# Getting Started\n\n## Installation\n\n```bash\nnpm install\n```"
-f title="Getting Started"
-f content="# Getting Started\n\n## Installation\n\n```bash\nnpm install\n```"
Create API reference
创建API参考文档
glab api projects/$project_id/wikis --method POST
-f title="API Reference"
-f content="# API Reference\n\n## Endpoints\n\n| Method | Path | Description |\n|--------|------|-------------|\n| GET | /users | List users |"
-f title="API Reference"
-f content="# API Reference\n\n## Endpoints\n\n| Method | Path | Description |\n|--------|------|-------------|\n| GET | /users | List users |"
undefinedglab api projects/$project_id/wikis --method POST
-f title="API Reference"
-f content="# API Reference\n\n## Endpoints\n\n| Method | Path | Description |\n|--------|------|-------------|\n| GET | /users | List users |"
-f title="API Reference"
-f content="# API Reference\n\n## Endpoints\n\n| Method | Path | Description |\n|--------|------|-------------|\n| GET | /users | List users |"
undefinedWorkflow 2: Backup Wiki Content
工作流2:备份Wiki内容
bash
undefinedbash
undefinedList all pages and save content
列出所有页面并保存内容
mkdir -p wiki_backup
glab api projects/123/wikis --paginate | jq -r '.[].slug' | while read slug; do
echo "Backing up: $slug"
glab api "projects/123/wikis/$(echo "$slug" | jq -Rr @uri)" |
jq -r '.content' > "wiki_backup/${slug////_}.md" done
jq -r '.content' > "wiki_backup/${slug////_}.md" done
undefinedmkdir -p wiki_backup
glab api projects/123/wikis --paginate | jq -r '.[].slug' | while read slug; do
echo "Backing up: $slug"
glab api "projects/123/wikis/$(echo "$slug" | jq -Rr @uri)" |
jq -r '.content' > "wiki_backup/${slug////_}.md" done
jq -r '.content' > "wiki_backup/${slug////_}.md" done
undefinedWorkflow 3: Migrate Wiki Content
工作流3:迁移Wiki内容
bash
undefinedbash
undefinedGet page from source project
从源项目获取页面内容
content=$(glab api projects/123/wikis/home | jq -r '.content')
title=$(glab api projects/123/wikis/home | jq -r '.title')
content=$(glab api projects/123/wikis/home | jq -r '.content')
title=$(glab api projects/123/wikis/home | jq -r '.title')
Create in target project
在目标项目中创建页面
glab api projects/456/wikis --method POST
-f title="$title"
-f content="$content"
-f title="$title"
-f content="$content"
undefinedglab api projects/456/wikis --method POST
-f title="$title"
-f content="$content"
-f title="$title"
-f content="$content"
undefinedWorkflow 4: Add Image to Wiki Page
工作流4:向Wiki页面添加图片
bash
undefinedbash
undefined1. Upload image
1. 上传图片
response=$(glab api projects/123/wikis/attachments --method POST -F "file=@diagram.png")
response=$(glab api projects/123/wikis/attachments --method POST -F "file=@diagram.png")
2. Get markdown link
2. 获取Markdown链接
markdown_link=$(echo "$response" | jq -r '.link.markdown')
markdown_link=$(echo "$response" | jq -r '.link.markdown')
3. Update page to include image
3. 更新页面以包含图片
current_content=$(glab api projects/123/wikis/architecture | jq -r '.content')
new_content="$current_content
current_content=$(glab api projects/123/wikis/architecture | jq -r '.content')
new_content="$current_content
Diagram
Diagram
$markdown_link"
glab api projects/123/wikis/architecture --method PUT
-f content="$new_content"
-f content="$new_content"
undefined$markdown_link"
glab api projects/123/wikis/architecture --method PUT
-f content="$new_content"
-f content="$new_content"
undefinedWorkflow 5: List All Wiki Pages with Titles
工作流5:列出所有带标题的Wiki页面
bash
glab api projects/123/wikis --paginate | \
jq -r '.[] | "[\(.title)](\(.slug))"'bash
glab api projects/123/wikis --paginate | \
jq -r '.[] | "[\(.title)](\(.slug))"'Wiki Slugs
Wiki Slugs
Slugs are URL-safe versions of titles:
- Spaces become hyphens: →
Getting StartedGetting-Started - Special characters are removed
- Case is preserved
For nested pages, use directory structure in slug:
- creates a page under
guides/installationguides/
Slugs是标题的URL安全版本:
- 空格会变为连字符:→
Getting StartedGetting-Started - 特殊字符会被移除
- 大小写会被保留
对于嵌套页面,在slug中使用目录结构:
- 会在
guides/installation目录下创建页面。guides/
Troubleshooting
故障排除
| Issue | Cause | Solution |
|---|---|---|
| 404 Not Found | Wiki disabled or page doesn't exist | Enable wiki in project settings, check slug |
| 403 Forbidden | No write access | Need Developer+ role or check wiki permissions |
| Empty content | Encoding issue | Check content string escaping |
| Slug mismatch | Auto-generated slug differs | Explicitly set |
| Upload fails | Wrong content type | Use |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 404 Not Found | Wiki未启用或页面不存在 | 在项目设置中启用Wiki,检查slug是否正确 |
| 403 Forbidden | 无写入权限 | 需要Developer及以上权限,或检查Wiki权限设置 |
| 内容为空 | 编码问题 | 检查内容字符串的转义是否正确 |
| Slug不匹配 | 自动生成的slug与预期不符 | 显式设置 |
| 上传失败 | 内容类型错误 | 文件上传使用 |
Best Practices
最佳实践
- Use meaningful slugs: Keep URLs readable and consistent
- Create a home page: Start with a home/index page
- Use relative links: Link between wiki pages using slugs
- Organize with structure: Use slug directories for organization
- Include images: Upload screenshots and diagrams for clarity
- 使用有意义的slug:保持URL可读且一致
- 创建首页:从首页/索引页开始构建Wiki
- 使用相对链接:通过slug在Wiki页面之间创建链接
- 结构化组织:使用slug目录结构进行内容分类
- 添加图片:上传截图和图表以提升内容清晰度
Related Documentation
相关文档
- API Helpers
- Safeguards
- Quick Reference
- GitLab Wiki API
- API 助手
- 安全防护
- 快速参考
- GitLab Wiki API