Operations 11 min read

How to Build and Deploy a Hexo Blog on GitHub Pages with CI/CD

This guide walks through selecting a blogging solution, setting up a Hexo site locally, deploying it to GitHub Pages using GitHub Actions, adding a theme, enabling comments, and mirroring the repository to Gitee for faster access, providing step‑by‑step commands and configuration files.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Build and Deploy a Hexo Blog on GitHub Pages with CI/CD

Preface

Ways to Build a Blog

1. Use online blog platforms such as Yuque, Juejin, CSDN, etc.

Advantages: create an account and start immediately, simple, no maintenance.

Disadvantages: articles are scattered across platforms, hard to manage.

2. GitHub Pages + static generators like Hugo, Hexo (highly recommended).

Advantages: all articles are under your control, easy to manage, and you can learn many related technologies while building from scratch.

Disadvantages: only static content, no backend management system.

3. WordPress (not used here).

Advantages: easy backup and migration, powerful extensions, friendly for custom users, built‑in backend management.

Disadvantages: many features make it unfriendly for beginners.

Personal Choice

I chose the second option: github pages + hexo, which lets me learn GitHub Actions, GitHub Pages, GitHub Discussions, and have a personal blog to showcase on my résumé.

Body

How to Set Up

First, create a local Hexo site.

$ npm install hexo-cli -g
$ hexo init blog
$ cd blog
$ npm install
$ hexo server

Visit the local server to see the site.

Add a new article: hexo new <em>post-title</em> The command creates a markdown file under source/_posts where you can write content.

Deploy Hexo to GitHub Pages

Create a repository on GitHub and push the Hexo files to the default branch ( main or master). $ git push -u origin main Ensure public/ is excluded via .gitignore.

Configure GitHub Pages to use GitHub Actions as the source, then add a workflow file .github/workflows/pages.yml:

name: Pages
on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          submodules: recursive
      - name: Use Node.js 16.x
        uses: actions/setup-node@v2
        with:
          node-version: '16'
      - name: Cache NPM dependencies
        uses: actions/cache@v2
        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@v2
        with:
          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@v2

After the workflow runs, the site is available at the GitHub Pages URL.

Advanced: Theme and Comments

Install a Hexo theme, e.g., Icarus:

$ npm install hexo-theme-icarus
$ hexo config theme icarus

Configure the generated _config.icarus.yml as needed.

For comments, you can use Changyan, Giscus, or Gitalk.

Mirror to Gitee and Deploy Gitee Pages

Add a job to the workflow to mirror the repository to Gitee:

mirroring-gitee:
  needs: [build, deploy]
  runs-on: ubuntu-latest
  steps:
    - name: Use Node.js 16.x
      uses: actions/setup-node@v2
      with:
        node-version: '16'
    - name: Mirror the Github organization repos to Gitee.
      uses: Yikun/hub-mirror-action@master
      with:
        src: 'github/YourGitHubOrg'
        dst: 'gitee/YourGiteeOrg'
        dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
        dst_token: ${{ secrets.GITEE_TOKEN }}
        static_list: "your-blog-repo"
        force_update: true
        timeout: '5m'

Configure the necessary secrets and SSH keys in both GitHub and Gitee as described.

After the workflow finishes, the site is also available on Gitee Pages, providing faster access in regions where GitHub is slow.

Now you can add new posts with hexo new <em>title</em> and push them to the remote repository.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdGiteehexostatic siteGitHub Pages
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.