|
| 1 | +name: Deploy Nextra Docs to gh-pages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + paths: |
| 7 | + - 'nextra-docs-zh/**' |
| 8 | + - 'nextra-docs-en/**' |
| 9 | + - '.github/workflows/deploy-docs.yml' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +# 设置权限 |
| 13 | +permissions: |
| 14 | + contents: write # 需要写权限以推送到 gh-pages 分支 |
| 15 | + |
| 16 | +jobs: |
| 17 | + deploy: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Setup Node.js |
| 24 | + uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: '20' |
| 27 | + cache: 'npm' |
| 28 | + cache-dependency-path: | |
| 29 | + nextra-docs-zh/package-lock.json |
| 30 | + nextra-docs-en/package-lock.json |
| 31 | +
|
| 32 | + - name: Install dependencies (Chinese docs) |
| 33 | + run: | |
| 34 | + cd nextra-docs-zh |
| 35 | + npm ci --force |
| 36 | +
|
| 37 | + - name: Build Chinese docs |
| 38 | + run: | |
| 39 | + cd nextra-docs-zh |
| 40 | + npm run build |
| 41 | +
|
| 42 | + - name: Install dependencies (English docs) |
| 43 | + run: | |
| 44 | + cd nextra-docs-en |
| 45 | + npm ci --force |
| 46 | +
|
| 47 | + - name: Build English docs |
| 48 | + run: | |
| 49 | + cd nextra-docs-en |
| 50 | + npm run build |
| 51 | +
|
| 52 | + - name: Prepare deployment |
| 53 | + run: | |
| 54 | + mkdir -p deploy |
| 55 | + # Copy Chinese docs from out/react-markdown-typer/zh to deploy/react-markdown-typer/zh |
| 56 | + if [ -d "nextra-docs-zh/out/react-markdown-typer/zh" ]; then |
| 57 | + mkdir -p deploy/react-markdown-typer |
| 58 | + cp -r nextra-docs-zh/out/react-markdown-typer/zh deploy/react-markdown-typer/ |
| 59 | + fi |
| 60 | + # Copy English docs from out/react-markdown-typer/en to deploy/react-markdown-typer/en |
| 61 | + if [ -d "nextra-docs-en/out/react-markdown-typer/en" ]; then |
| 62 | + mkdir -p deploy/react-markdown-typer |
| 63 | + cp -r nextra-docs-en/out/react-markdown-typer/en deploy/react-markdown-typer/ |
| 64 | + fi |
| 65 | + # Create root index.html to redirect to zh |
| 66 | + echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=/react-markdown-typer/zh/"><script>window.location.href="/react-markdown-typer/zh/";</script></head><body><a href="/react-markdown-typer/zh/">Redirecting...</a></body></html>' > deploy/index.html |
| 67 | +
|
| 68 | + - name: Deploy to gh-pages branch |
| 69 | + uses: peaceiris/actions-gh-pages@v3 |
| 70 | + with: |
| 71 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + publish_dir: ./deploy |
| 73 | + publish_branch: gh-pages |
| 74 | + force_orphan: true # 清理历史,只保留最新的部署 |
| 75 | + # 如果需要自定义域名,取消下面的注释 |
| 76 | + # cname: your-domain.com |
| 77 | + |
0 commit comments