The following code is modified from the Hexo official documentation: Deploy Hexo on GitHub Pages. This tutorial needs to be used in conjunction with the above or other tutorials.
Before using, please create .github/workflows/xxx.yml
in the repository, with a name of your choice.
This workflow file mainly implements the following process:
Users modify articles in Hexo locally, synchronize changes to GitHub, trigger GitHub Actions, generate new static files according to .github/workflows/xxx.yml
, and update the files to the gh-pages
branch (customizable) within the same repository. Netlify/Vercel can then pull the gh-pages
branch through pre-configuration and directly deploy the website.
Compared to other methods, this approach moves the build process to GitHub Actions.
The last step uses the peaceiris/actions-gh-pages
workflow preset, which has more features. For details, please refer to: GitHub Pages action - GitHub Marketplace
name: Build and Deploy # Customizable workflow name
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
submodules: recursive
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Cache NPM dependencies
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
restore-keys: |
${{ runner.OS }}-npm-cache
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public # Customizable Hexo output directory
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public # Customizable Hexo output directory
publish_branch: gh-pages # Customizable output branch