File tree Expand file tree Collapse file tree 12 files changed +9381
-0
lines changed
Expand file tree Collapse file tree 12 files changed +9381
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Deploy GitHub Pages
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ - dev_0_6_0
8+ workflow_dispatch :
9+
10+ permissions :
11+ contents : read
12+ pages : write
13+ id-token : write
14+
15+ concurrency :
16+ group : pages
17+ cancel-in-progress : true
18+
19+ jobs :
20+ build :
21+ runs-on : ubuntu-latest
22+ steps :
23+ - name : Checkout
24+ uses : actions/checkout@v4
25+
26+ - name : Setup Node
27+ uses : actions/setup-node@v4
28+ with :
29+ node-version : 20
30+ cache : npm
31+ cache-dependency-path : docs/site/package-lock.json
32+
33+ - name : Install
34+ working-directory : docs/site
35+ run : npm ci
36+
37+ - name : Build
38+ working-directory : docs/site
39+ env :
40+ REPO_NAME : ${{ github.event.repository.name }}
41+ BASE_PATH : /${{ github.event.repository.name }}/
42+ run : npm run build
43+
44+ - name : Upload artifact
45+ uses : actions/upload-pages-artifact@v3
46+ with :
47+ path : docs/site/dist
48+
49+ deploy :
50+ needs : build
51+ runs-on : ubuntu-latest
52+ environment :
53+ name : github-pages
54+ url : ${{ steps.deployment.outputs.page_url }}
55+ steps :
56+ - name : Deploy to GitHub Pages
57+ id : deployment
58+ uses : actions/deploy-pages@v4
59+
Original file line number Diff line number Diff line change 1+ site /node_modules /
2+ site /.astro /
3+ site /.cache /
4+ site /dist /
5+
6+ # 避免误提交旧的 /docs 发布产物
7+ index.html
8+ logo.png
9+ assets /
Original file line number Diff line number Diff line change 1+ # openhare 官网(静态站点)
2+
3+ 本目录用于 GitHub Pages 发布的静态官网。
4+
5+ ## 目录结构
6+
7+ - ` docs/ ` :官网文档目录
8+ - ` docs/site/ ` :Astro 项目源码(开发、构建用)
9+
10+ ## 语言
11+
12+ - 中文:` / `
13+ - English:` /en/ `
14+
15+ ## 本地开发
16+
17+ ``` bash
18+ cd docs/site
19+ npm install
20+ npm run dev
21+ ```
22+
23+ ## 构建(输出到 docs/site/dist)
24+
25+ ``` bash
26+ cd docs/site
27+ npm run build
28+ ```
29+
30+ 构建完成后应能看到:
31+
32+ - ` docs/site/dist/index.html `
33+ - ` docs/site/dist/assets/... `
34+
35+ > 注意:构建产物不提交到主分支,由 GitHub Actions 负责构建并发布到 GitHub Pages。
36+
37+ ## GitHub Pages 发布
38+
39+ 在 GitHub 仓库中打开 ** Settings → Pages** :
40+
41+ - ** Source** :GitHub Actions
42+
43+ 然后推送代码即可自动构建并发布。
44+
45+ ## 配置 base 路径(重要)
46+
47+ 如果你的 Pages 地址是 ` https://<user>.github.io/<repo>/ ` ,则需要设置 base 为 ` /<repo>/ ` 。
48+
49+ 本项目在 CI 中会根据仓库名自动注入 ` BASE_PATH ` (例如 ` /openhare/ ` ),本地默认按仓库名 ` openhare ` 配置。需要调整时,编辑:
50+
51+ - ` docs/site/astro.config.mjs `
52+
53+ 对应的 Pages 工作流文件:
54+
55+ - ` .github/workflows/pages.yml `
56+
Original file line number Diff line number Diff line change 1+ import { defineConfig } from 'astro/config' ;
2+
3+ /**
4+ * GitHub Pages 通常发布在子路径:
5+ * https://<user>.github.io/<repo>/
6+ * 因此需要设置 base 为 `/<repo>/`。
7+ */
8+ const repoName = process . env . REPO_NAME ?? 'openhare' ;
9+ const base = process . env . BASE_PATH ?? `/${ repoName } /` ;
10+
11+ export default defineConfig ( {
12+ // 构建产物输出到本项目 dist,由 GitHub Actions 发布到 Pages
13+ outDir : './dist' ,
14+ base,
15+ build : {
16+ // 将默认的 `_astro/` 改为更通用的目录名
17+ assets : 'assets' ,
18+ } ,
19+
20+ // dist 可安全清空
21+ vite : {
22+ build : {
23+ emptyOutDir : true ,
24+ } ,
25+ } ,
26+ } ) ;
27+
You can’t perform that action at this time.
0 commit comments