gitlab-wiki

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Wiki Skill

Wiki技能

Wiki page management for GitLab using
glab api
raw endpoint calls.
使用
glab api
原始端点调用进行GitLab Wiki页面管理。

Quick Reference

快速参考

OperationCommand PatternRisk
List pages
glab api projects/:id/wikis
-
Get page
glab api projects/:id/wikis/:slug
-
Create page
glab api projects/:id/wikis -X POST -f ...
⚠️
Update page
glab api projects/:id/wikis/:slug -X PUT -f ...
⚠️
Delete page
glab api projects/:id/wikis/:slug -X DELETE
⚠️⚠️
Upload attachment
glab api projects/:id/wikis/attachments -X POST ...
⚠️
Risk Legend: - Safe | ⚠️ Caution | ⚠️⚠️ Warning | ⚠️⚠️⚠️ Danger
操作命令模板风险
列出页面
glab api projects/:id/wikis
-
获取页面
glab api projects/:id/wikis/:slug
-
创建页面
glab api projects/:id/wikis -X POST -f ...
⚠️
更新页面
glab api projects/:id/wikis/:slug -X PUT -f ...
⚠️
删除页面
glab api projects/:id/wikis/:slug -X DELETE
⚠️⚠️
上传附件
glab api projects/:id/wikis/attachments -X POST ...
⚠️
风险说明: - 安全 | ⚠️ 注意 | ⚠️⚠️ 警告 | ⚠️⚠️⚠️ 危险

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
    wiki_blobs
    scope)
  • 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:
api
Permissions:
  • 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
undefined
bash
undefined

List 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"
undefined
glab api "projects/$(echo 'mygroup/myproject' | jq -Rr @uri)/wikis"
undefined

Get Wiki Page

获取Wiki页面

bash
undefined
bash
undefined

Get 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
undefined
glab api "projects/123/wikis/home?render_html=true" --method GET
undefined

Create Wiki Page

创建Wiki页面

bash
undefined
bash
undefined

Create simple page

创建简单页面

glab api projects/123/wikis --method POST
-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!"

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

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..."
glab api projects/123/wikis --method POST
-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..."
undefined
glab api projects/123/wikis --method POST
-f title="Database Setup"
-f slug="guides/database-setup"
-f content="# Database Setup\n\nConfiguration steps..."
undefined

Update Wiki Page

更新Wiki页面

bash
undefined
bash
undefined

Update 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..."
glab api "projects/123/wikis/$(echo 'Getting Started' | jq -Rr @uri)" --method PUT
-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."
glab api projects/123/wikis/home --method PUT
-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."
undefined
glab api projects/123/wikis/readme --method PUT
-f format="asciidoc"
-f content="= README\n\nAsciidoc content here."
undefined

Delete Wiki Page

删除Wiki页面

bash
undefined
bash
undefined

Delete 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
undefined
glab api "projects/123/wikis/$(echo 'drafts/temp-page' | jq -Rr @uri)" --method DELETE
undefined

Upload Attachment

上传附件

bash
undefined
bash
undefined

Upload image

上传图片

glab api projects/123/wikis/attachments --method POST
-F "file=@screenshot.png"
glab api projects/123/wikis/attachments --method POST
-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":"screenshot"}}

{"file_name":"screenshot.png","file_path":"uploads/...","branch":"master","link":{"url":"...","markdown":"screenshot"}}

undefined
undefined

Wiki Page Options

Wiki页面选项

OptionTypeDescription
title
stringPage title (required for create)
slug
stringPage URL slug (auto-generated from title if not provided)
content
stringPage content
format
stringContent format:
markdown
(default),
rdoc
,
asciidoc
选项类型描述
title
字符串页面标题(创建时必填)
slug
字符串页面URL别名(若未提供则自动从标题生成)
content
字符串页面内容
format
字符串内容格式:
markdown
(默认)、
rdoc
asciidoc

Format Support

格式支持

FormatExtensionDescription
markdown
.md
GitHub-flavored Markdown
rdoc
.rdoc
Ruby documentation format
asciidoc
.asciidoc
AsciiDoc format
org
.org
Org mode format
格式扩展名描述
markdown
.md
GitHub风格Markdown
rdoc
.rdoc
Ruby文档格式
asciidoc
.asciidoc
AsciiDoc格式
org
.org
Org模式格式

Common Workflows

常见工作流

Workflow 1: Create Documentation Structure

工作流1:创建文档结构

bash
project_id=123
bash
project_id=123

Create 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"
glab api projects/$project_id/wikis --method POST
-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```"
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```"

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

Workflow 2: Backup Wiki Content

工作流2:备份Wiki内容

bash
undefined
bash
undefined

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

Workflow 3: Migrate Wiki Content

工作流3:迁移Wiki内容

bash
undefined
bash
undefined

Get 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"
undefined
glab api projects/456/wikis --method POST
-f title="$title"
-f content="$content"
undefined

Workflow 4: Add Image to Wiki Page

工作流4:向Wiki页面添加图片

bash
undefined
bash
undefined

1. 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"
undefined
$markdown_link"
glab api projects/123/wikis/architecture --method PUT
-f content="$new_content"
undefined

Workflow 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 Started
    Getting-Started
  • Special characters are removed
  • Case is preserved
For nested pages, use directory structure in slug:
  • guides/installation
    creates a page under
    guides/
Slugs是标题的URL安全版本:
  • 空格会变为连字符:
    Getting Started
    Getting-Started
  • 特殊字符会被移除
  • 大小写会被保留
对于嵌套页面,在slug中使用目录结构:
  • guides/installation
    会在
    guides/
    目录下创建页面。

Troubleshooting

故障排除

IssueCauseSolution
404 Not FoundWiki disabled or page doesn't existEnable wiki in project settings, check slug
403 ForbiddenNo write accessNeed Developer+ role or check wiki permissions
Empty contentEncoding issueCheck content string escaping
Slug mismatchAuto-generated slug differsExplicitly set
slug
parameter
Upload failsWrong content typeUse
-F
flag for file uploads
问题原因解决方案
404 Not FoundWiki未启用或页面不存在在项目设置中启用Wiki,检查slug是否正确
403 Forbidden无写入权限需要Developer及以上权限,或检查Wiki权限设置
内容为空编码问题检查内容字符串的转义是否正确
Slug不匹配自动生成的slug与预期不符显式设置
slug
参数
上传失败内容类型错误文件上传使用
-F
标志

Best Practices

最佳实践

  1. Use meaningful slugs: Keep URLs readable and consistent
  2. Create a home page: Start with a home/index page
  3. Use relative links: Link between wiki pages using slugs
  4. Organize with structure: Use slug directories for organization
  5. Include images: Upload screenshots and diagrams for clarity
  1. 使用有意义的slug:保持URL可读且一致
  2. 创建首页:从首页/索引页开始构建Wiki
  3. 使用相对链接:通过slug在Wiki页面之间创建链接
  4. 结构化组织:使用slug目录结构进行内容分类
  5. 添加图片:上传截图和图表以提升内容清晰度

Related Documentation

相关文档