npx skills add https://github.com/alfredang/skills --skill 'GitHub Pages'/github-page 或 github-page
部署
github pages, deploy pages, static site, gh-pages, github actions, deploy website, host website, github hosting, deploy static, pages deploy, free hosting, github site, publish site, deploy html, deploy react to github
无需手动配置,即可将任何项目部署到 GitHub Pages。自动检测项目类型,生成正确的 GitHub Actions 工作流,通过 API 在仓库中启用 GitHub Pages 和 Actions,并提供一个实时 URL。
此技能使用 Claude Code 订阅计划 运行。请勿使用按量付费的 API 密钥。所有 AI 操作都应在具有活动订阅的 Claude Code CLI 环境中执行。
我将帮助您部署到 GitHub Pages!
工作流程包括:
| 步骤 | 描述 |
|---|---|
| 预检 | 验证 gh CLI、git 远程仓库和仓库访问权限 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 检测项目 | 自动检测项目类型和构建配置 |
| 生成工作流 | 创建 .github/workflows/deploy-pages.yml |
| 推送和启用 | 推送工作流,通过 API 启用 GitHub Pages 和 Actions |
| 验证 | 确认部署并提供实时 URL |
执行 /github-page 时,请遵循此工作流程:
gh --version
如果未安装,通知用户:
ERROR: GitHub CLI (gh) not found.
Install: https://cli.github.com/
gh auth status
如果未通过身份验证:
ERROR: Not logged in to GitHub CLI.
Run: gh auth login
git remote get-url origin
从远程 URL 提取 OWNER 和 REPO:
# For HTTPS: https://github.com/OWNER/REPO.git
# For SSH: git@github.com:OWNER/REPO.git
REMOTE_URL=$(git remote get-url origin)
OWNER=$(echo "$REMOTE_URL" | sed -E 's#.*(github\.com)[:/]([^/]+)/([^/.]+)(\.git)?$#\2#')
REPO=$(echo "$REMOTE_URL" | sed -E 's#.*(github\.com)[:/]([^/]+)/([^/.]+)(\.git)?$#\3#')
如果不存在远程仓库:
ERROR: No GitHub remote found.
Add one with: git remote add origin https://github.com/USER/REPO.git
分析项目以确定构建命令和输出目录。
| 指示器 | 项目类型 | 构建命令 | 输出目录 |
|---|---|---|---|
vite.config.* | Vite (React/Vue/Svelte) | npm install && npm run build | ./dist |
next.config.* | Next.js (静态导出) | npm install && npm run build | ./out |
angular.json | Angular | npm install && npm run build | ./dist/<project> |
package.json 包含 build 脚本 | Node.js 项目 | npm install && npm run build | ./dist 或 ./build |
根目录下的 index.html | 静态 HTML | 无 | ./ |
public/index.html | public/ 目录下的静态文件 | 无 | ./public |
requirements.txt + mkdocs.yml | MkDocs | pip install -r requirements.txt && mkdocs build | ./site |
| 以上均不符合 | 未知 | 询问用户 | 询问用户 |
Vite 项目 — 确保在 vite.config.* 中设置了 base:
export default defineConfig({
base: '/<REPO>/',
})
如果未设置 base,请通知用户 — 没有它,站点的资源路径将会损坏。
Next.js 项目 — 确保 next.config.* 中包含 output: 'export':
const nextConfig = {
output: 'export',
basePath: '/<REPO>',
}
检查 .nvmrc、.node-version 或 package.json 中的 engines.node,以在工作流中设置正确的 Node.js 版本。如果未指定,则默认为 20。
创建 .github/workflows/deploy-pages.yml:
name: Deploy to GitHub Pages
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: '.'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
name: Deploy to GitHub Pages
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '<NODE_VERSION>'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: '<OUTPUT_DIR>'
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
将 <NODE_VERSION> 和 <OUTPUT_DIR> 替换为从阶段 2 检测到的值。
mkdir -p .github/workflows
将适当的工作流 YAML 写入 .github/workflows/deploy-pages.yml。
git add .github/workflows/deploy-pages.yml
git commit -m "$(cat <<'EOF'
ci: add GitHub Pages deployment workflow
Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
git push origin main
重要: 始终添加特定文件。切勿使用 git add . 或 git add -A。
首先,检查 Pages 是否已启用:
gh api "/repos/$OWNER/$REPO/pages" 2>/dev/null
如果未启用 (404 响应),则创建它:
gh api -X POST "/repos/$OWNER/$REPO/pages" -f build_type=workflow
如果已启用但使用不同的源,则更新它:
gh api -X PUT "/repos/$OWNER/$REPO/pages" -f build_type=workflow
gh workflow enable deploy-pages.yml
gh workflow run deploy-pages.yml
等待几秒钟,然后检查:
gh run list --workflow=deploy-pages.yml --limit 1
=== GitHub Pages Deployment ===
Workflow: .github/workflows/deploy-pages.yml (created)
GitHub Pages: ENABLED (source: GitHub Actions)
GitHub Actions: ENABLED
Deployment URL: https://<OWNER>.github.io/<REPO>/
Workflow runs: https://github.com/<OWNER>/<REPO>/actions
Status: Deploying... (check Actions tab for progress)
Pages API 返回 409 (冲突):
工作流未触发:
确保分支名称匹配 (main 与 master)
检查 Actions 是否在仓库级别已启用:
gh api -X PUT "/repos/$OWNER/$REPO/actions/permissions" -f enabled=true
构建失败:
检查工作流运行日志:
gh run view --log
常见问题:Vite 缺少 base 配置,Next.js 缺少 output: 'export'
运行 /github-page 后:
https://github.com/<OWNER>/<REPO>/actionshttps://<OWNER>.github.io/<REPO>/main 分支将通过工作流自动部署每周安装次数
0
仓库
GitHub 星标数
1
首次出现时间
1970年1月1日
安全审计
/github-page or github-page
Deployment
github pages, deploy pages, static site, gh-pages, github actions, deploy website, host website, github hosting, deploy static, pages deploy, free hosting, github site, publish site, deploy html, deploy react to github
Deploy any project to GitHub Pages with zero manual configuration. Automatically detects your project type, generates the correct GitHub Actions workflow, enables GitHub Pages and Actions on the repo via API, and gives you a live URL.
This skill runs using Claude Code with subscription plan. Do NOT use pay-as-you-go API keys. All AI operations should be executed through the Claude Code CLI environment with an active subscription.
I'll help you deploy to GitHub Pages!
The workflow includes:
| Step | Description |
|---|---|
| Pre-flight | Verify gh CLI, git remote, and repo access |
| Detect Project | Auto-detect project type and build config |
| Generate Workflow | Create .github/workflows/deploy-pages.yml |
| Push & Enable | Push workflow, enable GitHub Pages + Actions via API |
| Verify | Confirm deployment and provide live URL |
When executing /github-page, follow this workflow:
gh --version
If not installed, inform the user:
ERROR: GitHub CLI (gh) not found.
Install: https://cli.github.com/
gh auth status
If not authenticated:
ERROR: Not logged in to GitHub CLI.
Run: gh auth login
git remote get-url origin
Extract OWNER and REPO from the remote URL:
# For HTTPS: https://github.com/OWNER/REPO.git
# For SSH: git@github.com:OWNER/REPO.git
REMOTE_URL=$(git remote get-url origin)
OWNER=$(echo "$REMOTE_URL" | sed -E 's#.*(github\.com)[:/]([^/]+)/([^/.]+)(\.git)?$#\2#')
REPO=$(echo "$REMOTE_URL" | sed -E 's#.*(github\.com)[:/]([^/]+)/([^/.]+)(\.git)?$#\3#')
If no remote exists:
ERROR: No GitHub remote found.
Add one with: git remote add origin https://github.com/USER/REPO.git
Analyze the project to determine build commands and output directory.
| Indicator | Project Type | Build Command | Output Dir |
|---|---|---|---|
vite.config.* | Vite (React/Vue/Svelte) | npm install && npm run build | ./dist |
next.config.* | Next.js (static export) | npm install && npm run build | ./out |
angular.json |
Vite projects — Ensure base is set in vite.config.*:
export default defineConfig({
base: '/<REPO>/',
})
Inform the user if base is not set — the site will have broken asset paths without it.
Next.js projects — Ensure output: 'export' is in next.config.*:
const nextConfig = {
output: 'export',
basePath: '/<REPO>',
}
Check for .nvmrc, .node-version, or engines.node in package.json to set the correct Node.js version in the workflow. Default to 20 if not specified.
Create .github/workflows/deploy-pages.yml:
name: Deploy to GitHub Pages
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: '.'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
name: Deploy to GitHub Pages
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '<NODE_VERSION>'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: '<OUTPUT_DIR>'
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
Replace <NODE_VERSION> and <OUTPUT_DIR> with detected values from Phase 2.
mkdir -p .github/workflows
Write the appropriate workflow YAML to .github/workflows/deploy-pages.yml.
git add .github/workflows/deploy-pages.yml
git commit -m "$(cat <<'EOF'
ci: add GitHub Pages deployment workflow
Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
git push origin main
Important: Always add specific files. Never use git add . or git add -A.
First, check if Pages is already enabled:
gh api "/repos/$OWNER/$REPO/pages" 2>/dev/null
If not enabled (404 response), create it:
gh api -X POST "/repos/$OWNER/$REPO/pages" -f build_type=workflow
If already enabled but using a different source, update it:
gh api -X PUT "/repos/$OWNER/$REPO/pages" -f build_type=workflow
gh workflow enable deploy-pages.yml
gh workflow run deploy-pages.yml
Wait a few seconds, then check:
gh run list --workflow=deploy-pages.yml --limit 1
=== GitHub Pages Deployment ===
Workflow: .github/workflows/deploy-pages.yml (created)
GitHub Pages: ENABLED (source: GitHub Actions)
GitHub Actions: ENABLED
Deployment URL: https://<OWNER>.github.io/<REPO>/
Workflow runs: https://github.com/<OWNER>/<REPO>/actions
Status: Deploying... (check Actions tab for progress)
Pages API returns 409 (conflict):
Workflow not triggering:
Ensure the branch name matches (main vs master)
Check if Actions are enabled at the repo level:
gh api -X PUT "/repos/$OWNER/$REPO/actions/permissions" -f enabled=true
Build fails:
Check the workflow run logs:
gh run view --log
Common issues: missing base config for Vite, missing output: 'export' for Next.js
After running /github-page:
https://github.com/<OWNER>/<REPO>/actionshttps://<OWNER>.github.io/<REPO>/main will auto-deploy via the workflowWeekly Installs
0
Repository
GitHub Stars
1
First Seen
Jan 1, 1970
Security Audits
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
147,400 周安装
| Angular |
npm install && npm run build |
./dist/<project> |
package.json with build script | Node.js project | npm install && npm run build | ./dist or ./build |
index.html in root | Static HTML | None | ./ |
public/index.html | Static in public/ | None | ./public |
requirements.txt + mkdocs.yml | MkDocs | pip install -r requirements.txt && mkdocs build | ./site |
| None of the above | Unknown | Ask user | Ask user |