跳转到内容

CLI 命令参考

Gridea Pro 除了图形界面外,还提供命令行工具,支持在无 GUI 环境下执行构建和部署操作,适合集成到 CI/CD 流水线中。

CLI 工具随 Gridea Pro 主程序一起安装。你也可以单独安装 CLI:

Terminal window
# macOS / Linux
curl -fsSL https://gridea.pro/install-cli.sh | bash
# 或通过 Go 安装
go install github.com/getgridea/gridea-pro/cmd/gridea@latest

构建静态站点:

Terminal window
# 在 Gridea 数据目录下执行
gridea build
# 指定源目录和输出目录
gridea build --source ~/Documents/Gridea --output ./dist
参数说明默认值
--source, -sGridea 数据目录当前目录
--output, -o输出目录./output
--theme, -t指定主题名称使用配置中的主题
--draft包含草稿文章false

启动本地预览服务器:

Terminal window
gridea serve
# 指定端口
gridea serve --port 8080
参数说明默认值
--port, -p服务器端口4000
--source, -sGridea 数据目录当前目录
--open自动打开浏览器false

启动后会监听文件变化并自动重新构建,适合主题开发时实时预览。

执行部署(推送到远程仓库):

Terminal window
gridea deploy
# 构建并部署
gridea build && gridea deploy

创建新文章:

Terminal window
# 创建文章
gridea new "我的新文章"
# 指定日期和标签
gridea new "技术分享" --date 2026-03-30 --tags "Go,博客"

初始化新主题脚手架:

Terminal window
gridea theme init my-theme --engine jinja2
参数说明
--engine模板引擎:jinja2(默认)、goejs

生成的目录结构包含 config.json、必需模板文件和示例样式。

验证主题语法和结构:

Terminal window
gridea theme validate ./themes/my-theme

检查内容包括:

  • config.json 格式是否正确
  • 必需模板文件是否存在
  • 模板标签是否配对
  • 变量名拼写是否正确

使用 mock 数据渲染主题进行测试:

Terminal window
gridea theme test ./themes/my-theme --output ./test-output
name: Build and Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Gridea CLI
run: curl -fsSL https://gridea.pro/install-cli.sh | bash
- name: Build
run: gridea build --source ./blog-data --output ./dist
- name: Deploy to Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
退出码含义
0成功
1一般错误
2配置错误
3模板渲染错误
4部署错误