# Halo CLI 命令参考 完整命令列表和详细用法。 ## 认证相关(auth) ```powershell # 查看当前认证状态 halo auth current # 列出所有配置 halo auth profile list # 登录(Bearer Token) halo auth login --profile local --url http://192.168.5.8:8090 --auth-type bearer --token # 登录(Basic Auth) halo auth login --profile local --url http://192.168.5.8:8090 --auth-type basic --username admin --password # 移除配置 halo auth remove local # 切换默认配置 halo auth default production ``` ## 文章管理(post) ### 列出文章 ```powershell # 基本列表 halo post list # 分页 halo post list --page 1 --size 20 # JSON 格式(便于脚本处理) halo post list --page 1 --size 20 --json # 按状态筛选 halo post list --status published halo post list --status draft ``` ### 获取文章 ```powershell # 查看文章详情 halo post get 019dbabc-86b9-74a0-a926-c25529309007 # JSON 格式 halo post get 019dbabc-86b9-74a0-a926-c25529309007 --json ``` ### 创建文章 ```powershell # 基本创建(草稿) halo post create --title "我的第一篇文章" --content "# 标题\n\n内容..." # 创建并发布 halo post create --title "我的第一篇文章" --content "# 标题" --publish true # 使用 HTML 格式 halo post create --title "HTML 文章" --content "

标题

内容

" --raw-type html # 指定分类 halo post create --title "文章" --content "内容" --category "技术" # 指定标签 halo post create --title "文章" --content "内容" --tags "Python,教程" ``` ### 更新文章 ```powershell # 更新标题 halo post update 019dbabc-86b9-74a0-a926-c25529309007 --title "新标题" # 更新内容 halo post update 019dbabc-86b9-74a0-a926-c25529309007 --content "# 新内容" # 同时更新标题和内容 halo post update 019dbabc-86b9-74a0-a926-c25529309007 --title "新标题" --content "新内容" # 更新标签 halo post update 019dbabc-86b9-74a0-a926-c25529309007 --tags "新标签1,新标签2" # 发布草稿 halo post update 019dbabc-86b9-74a0-a926-c25529309007 --publish true # 取消发布 halo post update 019dbabc-86b9-74a0-a926-c25529309007 --unpublish ``` ### 删除文章 ```powershell # 删除文章(会提示确认) halo post delete 019dbabc-86b9-74a0-a926-c25529309007 # 强制删除(跳过确认) halo post delete 019dbabc-86b9-74a0-a926-c25529309007 --force ``` ### 导出文章 ```powershell # 导出为 JSON halo post export-json 019dbabc-86b9-74a0-a926-c25529309007 # 导出到指定文件 halo post export-json 019dbabc-86b9-74a0-a926-c25529309007 --output ./backup/post.json # 导出为 Markdown halo post export-markdown 019dbabc-86b9-74a0-a926-c25529309007 # 导出到指定文件 halo post export-markdown 019dbabc-86b9-74a0-a926-c25529309007 --output ./backup/post.md ``` ### 导入文章 ```powershell # 从 JSON 文件导入 halo post import-json --file ./backup/post.json # 从 JSON 字符串导入 halo post import-json --raw '{"post": {...}, "content": "..."}' # 从 Markdown 文件导入 halo post import-markdown --file ./backup/post.md # 导入并发布 halo post import-markdown --file ./post.md --publish true ``` ### 文章标签管理 ```powershell # 列出所有标签 halo post tag list # 创建标签 halo post tag create --name "Python" --slug "python" --color "#3776AB" # 更新标签名称 halo post tag update python --name "Python编程" # 更新标签颜色 halo post tag update python --color "#3776AB" # 删除标签 halo post tag delete python # 查看标签下的文章数量 halo post tag list --verbose ``` ### 文章分类管理 ```powershell # 列出所有分类 halo post category list # 创建分类 halo post category create --name "技术" --slug "tech" --priority 10 # 更新分类 halo post category update tech --name "技术分享" --priority 5 # 删除分类 halo post category delete tech # 设置分类优先级(数字越大排序越靠前) halo post category update tech --priority 10 ``` ### 为文章设置标签和分类 ```powershell # 创建文章时设置标签 halo post create --title "标题" --content "内容" --tags "Python,教程" # 创建文章时设置分类 halo post create --title "标题" --content "内容" --category "技术" # 同时设置标签和分类 halo post create --title "标题" --content "内容" --tags "AI,教程" --category "技术" # 更新文章的标签 halo post update --tags "新标签1,新标签2" # 更新文章的分类 halo post update --category "技术分享" # 清除文章的标签 halo post update --tags "" # 清除文章的分类 halo post update --category "" ``` ### 查询文章标签和分类 ```powershell # 查看某篇文章的标签(JSON 格式) halo post get --json | Select-String -Pattern "tags" # 列出所有带有特定标签的文章 halo post list --page 1 --size 100 --json | ConvertFrom-Json | Where-Object { $_.spec.tags -contains "AI智能体" } # 列出所有带有特定分类的文章 halo post list --page 1 --size 100 --json | ConvertFrom-Json | Where-Object { $_.spec.categories -contains "技术深潜" } ``` ### 批量修改标签 ```powershell # 为所有无标签的文章添加标签 $posts = halo post list --page 1 --size 100 --json | ConvertFrom-Json foreach ($post in $posts.items) { if ($post.spec.tags.Count -eq 0) { halo post update $post.name --tags "技术深潜" Write-Host "已为 '$($post.spec.title)' 添加标签" } } # 将所有文章从"旧标签"迁移到"新标签" $posts = halo post list --page 1 --size 100 --json | ConvertFrom-Json foreach ($post in $posts.items) { if ($post.spec.tags -contains "旧标签") { $newTags = $post.spec.tags -replace "旧标签", "新标签" halo post update $post.name --tags ($newTags -join ",") } } ``` ### 博客现有标签参考 | 显示名称 | Slug | 颜色 | |---------|------|------| | 协会动态 | xie-hui-dong-tai | #B8E986 | | 5分钟速览 | 5fen-zhong-su-lan | #50E3C2 | | 技术深潜 | ji-shu-shen-qian | #4A90E2 | | 校园AI | xiao-yuan-ai | #9013FE | | 竞赛指南 | jing-sai-zhi-nan | #BD10E0 | | 项目实战 | xiang-mu-shi-zhan | #417505 | | 零基础入门 | ling-ji-chu-ru-men | #7ED321 | | 开源框架 | kai-yuan-kuang-jia | #8B572A | | 模型轻量化 | mo-xing-qing-liang-hua | #F8E71C | | 隐私计算 | yin-si-ji-suan | #F5A623 | | AI智能体 | aizhi-neng-ti | #D0021B | ### 博客现有分类参考 | 显示名称 | Slug | |---------|------| | 行业望远镜 | xing-ye-wang-yuan-jing | | 协会进行时 | xie-hui-jin-xing-shi | | 校园AI日记 | xiao-yuan-airi-ji | | 竞赛能量站 | jing-sai-neng-liang-zhan | | 成长实验室 | cheng-chang-shi-yan-shi | | 智能体前沿 | zhi-neng-ti-qian-yan | | 默认分类 | default | ## 单页管理(single-page) ```powershell # 列出单页 halo single-page list # 查看单页 halo single-page get # 创建单页 halo single-page create --title "关于我们" --content "公司介绍..." # 更新单页 halo single-page update about --title "关于我们" --content "新内容" # 删除单页 halo single-page delete about --force # 导出/导入 halo single-page export-markdown --output ./page.md halo single-page import-markdown --file ./page.md ``` ## 搜索内容(search) ```powershell # 搜索公开文章 halo search "Python 教程" # 搜索并限制结果 halo search "教程" --limit 10 # 搜索并显示详细信息 halo search "教程" --json ``` ## 插件管理(plugin) ```powershell # 列出插件 halo plugin list # 获取插件详情 halo plugin get # 升级插件 halo plugin upgrade # 升级所有插件 halo plugin upgrade --all # 启用/禁用插件 halo plugin enable halo plugin disable ``` ## 主题管理(theme) ```powershell # 列出主题 halo theme list # 获取主题详情 halo theme get # 升级主题 halo theme upgrade # 切换主题 halo theme active ``` ## 附件管理(attachment) ```powershell # 列出附件 halo attachment list # 上传附件 halo attachment upload --file ./image.png # 删除附件 halo attachment delete ``` ## 备份管理(backup) ```powershell # 列出备份 halo backup list # 创建备份 halo backup create # 下载备份 halo backup download --output ./backup.zip # 删除备份 halo backup delete ``` ## 动态管理(moment) ```powershell # 列出动态 halo moment list # 创建动态 halo moment create --content "今天写了两篇博客!" # 删除动态 halo moment delete ``` ## 评论管理(comment) ```powershell # 列出评论 halo comment list # 列出未审核评论 halo comment list --status pending # 回复评论 halo comment reply --content "感谢您的评论!" # 审核评论 halo comment approve halo comment reject # 删除评论 halo comment delete ``` ## 通知管理(notification) ```powershell # 列出通知 halo notification list # 标记已读 halo notification mark-read # 全部标记已读 halo notification mark-all-read # 删除通知 halo notification delete ``` ## Shell 补全 ```powershell # bash eval "$(halo completion bash)" # zsh eval "$(halo completion zsh)" # PowerShell(自动添加到配置文件) halo completion powershell >> $PROFILE ``` ## 输出格式 ### 普通输出 ```powershell # 表格格式(默认) halo post list # JSON 格式 halo post list --json # YAML 格式 halo post list --yaml ``` ### 颜色输出 ```powershell # 彩色输出(默认) halo post list --color # 禁用颜色 halo post list --no-color ``` ## 超时和重试 ```powershell # 设置超时(秒) halo post list --timeout 60 # 重试次数 halo post list --retry 3 ``` ## 调试 ```powershell # 显示调试信息 halo --debug post list # 显示完整错误 halo post create --title "Test" --content "Content" --verbose # 查看版本 halo --version # 查看帮助 halo --help halo post --help ```