Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the github actions workflow demo in github-pages.md #2149

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions source/docs/github-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ In this tutorial, we use [GitHub Actions](https://docs.github.com/en/actions) to
```
- The `public/` folder is not (and should not be) uploaded by default, make sure the `.gitignore` file contains `public/` line. The folder structure should be roughly similar to [this repo](https://github.com/hexojs/hexo-starter).

3. Check what version of Node.js you are using on your local machine with `node --version`. Make a note of the major version (e.g., `v16.y.z`)
3. Check what version of Node.js you are using on your local machine with `node --version`. Make a note of the major version (e.g., `v20.y.z`)
4. In your GitHub repo's setting, navigate to **Settings** > **Pages** > **Source**. Change the source to **GitHub Actions** and save.
5. Create `.github/workflows/pages.yml` in your repo with the following contents (substituting `16` to the major version of Node.js that you noted in previous step):
5. Create `.github/workflows/pages.yml` in your repo with the following contents (substituting `20` to the major version of Node.js that you noted in previous step):

```yml .github/workflows/pages.yml
name: Pages
Expand All @@ -29,17 +29,19 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
# If your repository depends on submodule, please see: https://github.com/actions/checkout
submodules: recursive
- name: Use Node.js 16.x
uses: actions/setup-node@v2
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: '16'
# Examples: 20, 18.19, >=16.20.2, lts/Iron, lts/Hydrogen, *, latest, current, node
# Ref: https://github.com/actions/setup-node#supported-version-syntax
node-version: '20'
- name: Cache NPM dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
Expand All @@ -50,7 +52,7 @@ jobs:
- name: Build
run: npm run build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
with:
path: ./public
deploy:
Expand All @@ -65,7 +67,7 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
```

6. Once the deployment is finished, check the webpage at *username*.github.io.
Expand Down
22 changes: 12 additions & 10 deletions source/zh-cn/docs/github-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,35 @@ title: 在 GitHub Pages 上部署 Hexo

- 默认情况下 `public/` 不会被上传(也不该被上传),确保 `.gitignore` 文件中包含一行 `public/`。整体文件夹结构应该与 [示例储存库](https://github.com/hexojs/hexo-starter) 大致相似。

3. 使用 `node --version` 指令检查你电脑上的 Node.js 版本,并记下该版本 (例如:`v16.y.z`)
3. 使用 `node --version` 指令检查你电脑上的 Node.js 版本,并记下该版本 (例如:`v20.y.z`)
4. 在储存库中前往 `Settings > Pages > Source`,并将 `Source` 改为 `GitHub Actions`。
5. 在储存库中建立 `.github/workflows/pages.yml`,并填入以下内容 (将 `16` 替换为上个步骤中记下的版本):
5. 在储存库中建立 `.github/workflows/pages.yml`,并填入以下内容 (将 `20` 替换为上个步骤中记下的版本):

```yml .github/workflows/pages.yml
name: Pages

on:
push:
branches:
- main # default branch
- main # default branch

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
# If your repository depends on submodule, please see: https://github.com/actions/checkout
submodules: recursive
- name: Use Node.js 16.x
uses: actions/setup-node@v2
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: '16'
# Examples: 20, 18.19, >=16.20.2, lts/Iron, lts/Hydrogen, *, latest, current, node
# Ref: https://github.com/actions/setup-node#supported-version-syntax
node-version: '20'
- name: Cache NPM dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
Expand All @@ -52,7 +54,7 @@ jobs:
- name: Build
run: npm run build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
with:
path: ./public
deploy:
Expand All @@ -67,7 +69,7 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
```

6. 部署完成后,前往 `https://<你的 GitHub 用户名>.github.io` 查看网站。
Expand Down
66 changes: 39 additions & 27 deletions source/zh-tw/docs/github-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ title: 在 GitHub Pages 上部署 Hexo

本文將使用 [GitHub Actions](https://docs.github.com/en/actions) 部屬至 GitHub Pages,此方法適用於公開或私人儲存庫。若你不希望將整個資料夾推上 GitHub,請參閱 [一鍵部屬](#一鍵部屬)。

1. 建立名為 <b>*username*.github.io</b> 的儲存庫,username 是你在 GitHub 上的使用者名稱,若之前已將 Hexo 上傳至其他儲存庫,將該儲存庫重命名即可。
1. 建立名為 `<你的 GitHub 使用者名稱>.github.io` 的儲存庫,username 是你在 GitHub 上的使用者名稱,若之前已將 Hexo 上傳至其他儲存庫,將該儲存庫重命名即可。
2. 將 Hexo 檔案 push 到儲存庫的預設分支,預設分支通常名為 **main**,舊一點的儲存庫可能名為 **master**。
- 將 `main` 分支 push 到 GitHub:

- 將 `main` 分支 push 到 GitHub:

```
$ git push -u origin main
```
- 預設情況下 `public/` 不會被上傳(也不該被上傳),確認 `.gitignore` 檔案中包含一行 `public/`。整體資料夾結構應會與[範例儲存庫](https://github.com/hexojs/hexo-starter)極為相似。

3. 使用 `node --version` 指令檢查你電腦上的 Node.js 版本,並記下該版本 (例如:`v16.y.z`)
4. 在儲存庫中建立 `.github/workflows/pages.yml`,並填入以下內容 (將 `16` 替換為上個步驟中記下的版本):
3. 使用 `node --version` 指令檢查你電腦上的 Node.js 版本,並記下該版本 (例如:`v20.y.z`)
4. 在儲存庫中前往 `Settings > Pages > Source`,並將 `Source` 改為 `GitHub Actions`。
5. 在儲存庫中建立 `.github/workflows/pages.yml`,並填入以下內容 (將 `20` 替換為上個步驟中記下的版本):

```yml .github/workflows/pages.yml
name: Pages
Expand All @@ -25,22 +27,22 @@ on:
- main # default branch

jobs:
pages:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
# If your repository depends on submodule, please see: https://github.com/actions/checkout
submodules: recursive
- name: Use Node.js 16.x
uses: actions/setup-node@v2
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: '16'
# Examples: 20, 18.19, >=16.20.2, lts/Iron, lts/Hydrogen, *, latest, current, node
# Ref: https://github.com/actions/setup-node#supported-version-syntax
node-version: '20'
- name: Cache NPM dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
Expand All @@ -50,31 +52,40 @@ jobs:
run: npm install
- name: Build
run: npm run build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
path: ./public
deploy:
needs: build
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
```

5. 當部屬作業完成後,產生的頁面會放在儲存庫中的 `gh-pages` 分支。
6. 在儲存庫中前往 **Settings** > **Pages** > **Source**,並將 branch 改為 `gh-pages`。
7. 前往 *username*.github.io 查看網站。
6. 當部屬作業完成後,前往 `https://<你的 GitHub 使用者名稱>.github.io` 檢視網站。

{% note info CNAME %}
若你使用 `CNAME` 自訂域名,你需要在 `source/` 資料夾中新增 `CNAME` 檔案。[更多資訊](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site)
{% endnote %}

## 專案頁面

如果你希望網站部署在 `<你的 GitHub 用戶名>.github.io` 的子目錄中:
如果你希望網站部署在 `<你的 GitHub 使用者名稱>.github.io` 的子目錄中:

1. 開啟你在 GitHub 的儲存庫,並前往 **Settings** 頁面。更改你的 **Repository name** 使你的部落格網址變成 <b>username.github.io/*repository*</b>,*repository* 可以是任何名稱,例如 *blog* 或 *hexo*。
2. 編輯你的 **_config.yml**,將 `url:` 更改為 <b>https://*username*.github.io/*repository*</b>。
3. Commit 並 push 到預設分支上。
4. 當部屬完成後,在 `gh-pages` 分支可以找到產生的網頁。
5. 在 GitHub 儲存庫中,前往 **Settings** > **Pages** > **Source**,並將 branch 改為 `gh-pages` 後儲存。
6. 前往 *username*.github.io/*repository* 查看。
1. 建立名為 `<repository 的名字>` 的儲存庫,這樣你的部落格網址為 `<你的 GitHub 使用者名稱>.github.io/<repository 的名字>`,repository 的名字可以任意,例如 blog 或 hexo。
2. 編輯你的 `_config.yml`,將 `url:` 更改為 `<你的 GitHub 使用者名稱>.github.io/<repository 的名字>`。
3. 在儲存庫中前往 `Settings > Pages > Source`,並將 `Source` 改為 `GitHub Actions`。
4. Commit 並 push 到預設分支上。
5. 部署完成後,前往 `https://<你的 GitHub 使用者名稱>.github.io/<repository 的名字>` 檢視網站。

## 一鍵部屬

Expand Down Expand Up @@ -102,4 +113,5 @@ jobs:
## 參考連結

- [GitHub Pages 使用文檔](https://help.github.com/categories/github-pages-basics/)
- [peaceiris/actions-gh-pages](https://github.com/marketplace/actions/github-pages-action)
- [使用自定义 GitHub Actions 工作流进行发布](https://docs.github.com/zh/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#使用自定义-github-actions-工作流进行发布)
- [actions/deploy-github-pages-site](https://github.com/marketplace/actions/deploy-github-pages-site)