forked from Gitlink/gitlink-cli
5.4 KiB
5.4 KiB
wiki +view
前置条件: 先阅读
../../gitlink-shared/SKILL.md了解认证、全局参数和安全规则。
查看指定 Wiki 页面的完整内容,包括 Markdown 源文本。
命令
# 查看 Wiki 页面内容
gitlink-cli wiki +view --title "Home"
# 查看指定仓库的 Wiki 页面
gitlink-cli wiki +view --owner Gitlink --repo forgeplus --title "API-Reference"
# 使用 JSON 格式查看(包含 base64 和 decoded 内容)
gitlink-cli wiki +view --title "Home" --format json
# 将 Wiki 内容保存到文件
gitlink-cli wiki +view --title "Home" --format json | jq -r ".data.content_decoded" > home.md
参数
| 参数 | Short | 必填 | 说明 |
|---|---|---|---|
--title |
-t |
是 | Wiki 页面标题(区分大小写) |
--owner |
否 | 仓库所有者(自动从 git remote 解析) | |
--repo |
否 | 仓库名称(自动从 git remote 解析) | |
--format |
否 | 输出格式: json/table/yaml |
|
--debug |
否 | 开启调试输出 |
返回字段
Table 格式
| 列名 | 说明 |
|---|---|
title |
Wiki 页面标题 |
content |
页面内容(自动解码后的文本) |
updated_at |
最后更新时间 |
JSON 格式
{
"ok": true,
"data": {
"title": "Home",
"content_base64": "I0hvbWUKCisqKldlbGNvbWUgdG8gdGhlIHByb2plY3QgIWJqKio=",
"content_decoded": "# Home\n\n**Welcome to the project!**\n\n## Getting Started\n...",
"updated_at": "2026-06-01T10:30:00Z"
}
}
字段说明:
content_base64- 原始 Base64 编码内容(API 返回)content_decoded- 自动解码后的文本内容(CLI 提供)
Workflow
- Confirm the page title with the user.
- Execute
gitlink-cli wiki +view --title "<page title>". - Display the page content (auto-decoded).
- Optional: Save content to file if requested.
API
GET https://gateway.gitlink.org.cn/api/wiki/open/getWiki
Query: owner={owner}&repo={repo}&projectId={project_id}&pageName={title}
工作流程:
- CLI 获取
project_id - 调用 Gateway API 获取页面
- 解码
content_base64为content_decoded - 返回解码后的内容
使用场景
场景 1: 查看单个页面
当用户询问"查看 API 文档页面"时:
gitlink-cli wiki +view --title "API Reference"
场景 2: 导出 Wiki 页面
# 导出为 Markdown 文件
gitlink-cli wiki +view --title "Home" --format json | \
jq -r ".data.content_decoded" > home.md
场景 3: 批量导出所有 Wiki 页面
#!/bin/bash
# 导出所有 Wiki 页面为 Markdown 文件
titles=$(gitlink-cli wiki +list --format json | jq -r ".data[].title")
for title in $titles; do
# 清理文件名(替换空格和特殊字符)
filename=$(echo "$title" | sed 's/[^a-zA-Z0-9_-]/_/g').md
echo "Exporting: $title -> $filename"
gitlink-cli wiki +view --title "$title" --format json | \
jq -r ".data.content_decoded" > "$filename"
done
场景 4: 检查页面是否存在
# 检查页面是否存在(退出码 0=存在,非0=不存在)
if gitlink-cli wiki +view --title "Some Page" >/dev/null 2>&1; then
echo "Page exists"
else
echo "Page does not exist"
fi
常见问题
Q: 提示 "page not found"?
A: 可能原因:
- 页面标题不匹配(区分大小写)
- 页面不存在
owner/repo指定错误
解决方法:
# 先列出所有页面确认标题
gitlink-cli wiki +list
Q: 内容显示为乱码?
A: 确保:
- 内容是有效的 UTF-8 编码
- 使用
--format json查看content_decoded字段 - 终端支持 UTF-8 显示
Q: 如何获取原始 Base64 内容?
A: 使用 JSON 格式查看 content_base64 字段:
gitlink-cli wiki +view --title "Home" --format json | jq ".data.content_base64"
Q: 支持哪些 Markdown 语法?
A: GitLink Wiki 支持 CommonMark 标准,包括:
- 标题、列表、代码块
- 链接、图片、表格
- 粗体、斜体、引用
错误处理
| 错误 | 原因 | 解决方案 |
|---|---|---|
required flag --title is missing |
未指定页面标题 | 添加 --title "Page Title" |
failed to fetch project_id |
项目不存在或无权限 | 检查 --owner 和 --repo |
failed to decode content |
Base64 解码失败 | 检查内容是否为有效 Base64 |
404 Not Found |
页面不存在 | 使用 wiki +list 查看可用页面 |
最佳实践
1. 页面标题规范
使用一致的命名规范:
# 推荐:使用连字符
"Getting-Started"
"API-Reference"
# 避免:空格和特殊字符
"Getting Started" # 需要引号
"API/Reference" # 斜杠可能被误解为路径
2. 内容验证
查看页面后验证内容完整性:
gitlink-cli wiki +view --title "Home" --format json | \
jq -r ".data.content_decoded" | wc -l
3. 批量操作
结合其他命令批量处理 Wiki:
# 查看所有页面的行数
for title in $(gitlink-cli wiki +list --format json | jq -r ".data[].title"); do
lines=$(gitlink-cli wiki +view --title "$title" --format json | \
jq -r ".data.content_decoded" | wc -l)
echo "$title: $lines lines"
done
References
- gitlink-wiki
- wiki +list — 列出 Wiki 页面
- wiki +create — 创建 Wiki 页面
- gitlink-shared