于 Github Pages 部署站点

赞助

成为我们的资助者或赞助商,以支持我们的工作。

赞助商

本教程展示如何于 GitHub Pages 部署站点。

为仓库启用 GitHub Pages

  1. 点击 Settings 标签。
  2. 打开 Pages.
  3. 选择 GitHUb Actions 作为 Source
  4. 可选:设置自定义域名。

创建 GitHub Pages 工作流程

创建以下工作流程,并提交到仓库。

.github/workflows/gh-pages.yaml
 1name: GitHub Pages
 2
 3on:
 4  # auto deploy when pushing to specified branches.
 5  push:
 6    branches:
 7      - main
 8
 9  # allow deploying manually.
10  workflow_dispatch:
11
12permissions:
13  contents: read
14  pages: write
15  id-token: write
16
17concurrency:
18  group: "pages"
19  cancel-in-progress: false
20
21defaults:
22  run:
23    shell: bash
24
25jobs:
26  build:
27    # Must runs on Ubuntu, since this workflow use snap to install Dart Sass.
28    runs-on: ubuntu-latest
29    steps:
30      - name: Checkout
31        uses: actions/checkout@v3
32        with:
33          submodules: recursive
34
35      - name: Setup Pages
36        id: pages
37        uses: actions/configure-pages@v3
38
39      - name: Setup Node
40        uses: actions/setup-node@v3
41        with:
42          node-version: "18"
43
44      - name: Setup Dart Sass
45        run: sudo snap install dart-sass && sudo snap alias dart-sass sass
46
47      - name: Setup Hugo
48        uses: peaceiris/actions-hugo@v2
49        with:
50          hugo-version: "latest"
51          extended: true
52
53      - name: Install Node.js dependencies
54        run: npm ci
55
56      - name: Build with Hugo
57        env:
58          HUGO_ENVIRONMENT: production
59          HUGO_ENV: production
60        run: |
61          hugo \
62            --gc \
63            --enableGitInfo \
64            --minify \
65            --baseURL "${{ steps.pages.outputs.base_url }}/"          
66
67      - name: Upload artifact
68        uses: actions/upload-pages-artifact@v1
69        with:
70          path: ./public
71
72  deploy:
73    environment:
74      name: github-pages
75      url: ${{ steps.deployment.outputs.page_url }}
76    runs-on: ubuntu-latest
77    needs: build
78    steps:
79      - name: Deploy to GitHub Pages
80        id: deployment
81        uses: actions/deploy-pages@v2
razonyang
2024年11月21日星期四 2023年4月14日星期五