Wiki.js 内容发布工具
功能概述
- •单文件发布:将 Markdown 文件发布到指定路径
- •批量发布:批量发布目录下所有 Markdown 文件
- •页面更新:更新已存在的页面内容
- •标签管理:为页面添加标签
配置
必需配置
在项目根目录创建 .env 文件:
bash
# Wiki.js 配置 WIKI_URL=http://wiki.example.com WIKI_TOKEN=your-api-token-here
可选配置
bash
WIKI_LOCALE=zh-cn # 默认语言 (默认: zh-cn) WIKI_EDITOR=markdown # 编辑器类型 (markdown/ckeditor/gmarkdown) WIKI_DEFAULT_PUBLISHED=true # 默认发布状态
使用方法
1. 发布单个文件
bash
node .opencode/skills/wiki-publish/scripts/wiki-publish.js publish \ --file path/to/document.md \ --path /docs/my-document
参数:
- •
--file, -f: Markdown 文件路径 (必需) - •
--path, -p: Wiki.js 目标路径 (必需) - •
--title, -t: 页面标题 (可选,默认从文件名提取) - •
--locale, -l: 语言 (可选,默认从配置读取) - •
--tags: 标签,逗号分隔 (可选)
2. 批量发布目录
bash
node .opencode/skills/wiki-publish/scripts/wiki-publish.js batch \ --dir path/to/docs \ --parent-path /docs
参数:
- •
--dir, -d: 包含 Markdown 文件的目录 (必需) - •
--parent-path, -p: 父路径,文件将发布到此路径下 (必需) - •
--recursive, -r: 递归处理子目录 (可选)
3. 更新页面
bash
node .opencode/skills/wiki-publish/scripts/wiki-publish.js update \ --file path/to/document.md \ --path /docs/my-document
4. 删除页面
bash
node .opencode/skills/wiki-publish/scripts/wiki-publish.js delete \ --path /docs/my-document
API 认证
- •登录 Wiki.js 管理后台
- •进入「API Access」设置
- •创建新的 API Token
- •确保 Token 包含以下权限:
- •
pages:create- 创建页面 - •
pages:update- 更新页面 - •
pages:delete- 删除页面 - •
pages:read- 读取页面
- •
GraphQL mutation 示例
创建页面:
graphql
mutation {
pages {
create(
content: "# Hello World\n\nThis is content.",
description: "Page description",
editor: "markdown",
isPublished: true,
isPrivate: false,
locale: "zh-cn",
path: "docs/hello",
tags: ["tag1", "tag2"],
title: "Hello World"
) {
responseResult {
message
success
}
page {
id
path
}
}
}
}
更新页面:
graphql
mutation {
pages {
update(
id: "page-id-here",
content: "# Updated Content",
editor: "markdown"
) {
responseResult {
message
success
}
}
}
}
常见问题
Q: 如何获取页面 ID?
使用 GraphQL 查询:
graphql
{
pages {
list {
id
path
title
}
}
}
Q: 如何处理图片?
图片需要单独上传到 Wiki.js 资产系统,然后在使用时引用其 URL。
Q: 发布失败怎么办?
检查:
- •API Token 是否有正确权限
- •目标路径是否已存在相同路径的页面
- •Markdown 内容是否符合 Wiki.js 格式要求
相关文件
- •wiki-publish.js - 主脚本
- •config.example.json - 配置示例