Rewrite README: reflect Gitea-hosted repo, rsync pipeline, and current stack
Deploy to website / deploy (push) Successful in 1m24s

This commit is contained in:
Leon Xu committed 2026-11-29 14:34:57 -08:00
1 parent a91d43ff9e
commit 81934dfc4c
1 file changed
+147 -393
+147 -393
View File
@@ -1,393 +1,147 @@
![Hexo Version](https://img.shields.io/badge/Hexo-5.4.0-blue.svg)
[![pipeline status](https://gitlab.com/leonxu260/hexo-butterfly/badges/master/pipeline.svg)](https://gitlab.com/leonxu260/hexo-butterfly/-/commits/master)
----
View site: https://www.angulareportfolio.pw
----
# Build an [Hexo] site with GitLab Pages
## Settings
- Theme: [Butterfly]
- GitLab CI - view [`.gitlab-ci.yml`]
- Hexo - view [`_config.yml`]
- Package - view [`package.json`]
## Requirements
[Hexo] is a [SSG] powered by [NodeJS][node]. So we'll need this first:
- Node JS environment
- [npm] (package manager)
- [git] core
## Script
We already have a Node image on [Docker Library][docker-lib], so we'll require it to run our script on the
environment of NodeJS.
This will bring `npm` and `git` core with it: `image: node:latest`
Then we'll need to run:
<br>
```
$ npm install -g hexo-cli
$ npm install
$ hexo generate
```
<br>
We'll set the the `npm` modules and its dependecies as a `cache` to speed up our builds:
<br>
```yaml
cache:
paths:
- node_modules/
```
### Current GitLab CI
Here is the current GitLab CI that I am using in my `gitlab-ci.yml`.
```yaml
build website:
stage: build
# requiring the environment of latest NodeJS version
image: node:latest
# add 'node_modules' to cache for speeding up builds
cache:
paths:
- node_modules/ # Node modules and dependencies
script:
- npm install -g hexo-cli # Install Hexo itself
- npm install # Install Hexo modules and dependencies
- npm install hexo-renderer-pug # Install Butterfly pug
- npm install hexo-renderer-stylus # Install stylus renderer
deploy to website:
stage: deploy
script:
- hexo clean # Hexo clean previous static site
- hexo generate # Hexo generate Static Site
- hexo deploy
only:
- master # this job will affect only the 'master' branch
```
### GitLab-CI with lftp
If I want GitLab CI/CD to deploy my website each time that I push to GitLab, I can use something called [lftp][lftp]. Here is what you can do in the `gitlab-ci.yml` configuration file.
<br>
```yaml
image: ubuntu:latest
before_script:
- apt update -qy # Check for update
- apt install -y lftp # Install lftp
- apt install curl # Install curl
- curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
- apt install nodejs # Install NodeJS
- npm install -g hexo-cli # Install Hexo itself
- npm install # Install Hexo modules and dependencies
- npm install hexo-renderer-pug # Install Butterfly pug
- npm install hexo-renderer-stylus # Install stylus renderer
deploy via lftp:
stage: deploy
script:
- hexo clean # Hexo clean previous static site
- hexo generate # Hexo generate Static Site
- lftp -e "mirror -R public/ $FTP_REMOTE_PATH/" -u $FTP_USER,$FTP_PASS $FTP_HOST $FTP_PORT
artifacts:
paths:
- public
only:
- master # this job will affect only the 'master' branch
```
### GitLab-CI
We need to prepare our `gitlab-ci.yml` configuration file to do as we described previously.
We'll also need a `pages` job and finally a `public` folder with our `artifacts`, affecting only our `master` branch:
<br>
```yaml
# requiring the environment of NodeJS 4.2.2
image: node:latest
# add 'node_modules' to cache for speeding up builds
cache:
paths:
- node_modules/ # Node modules and dependencies
before_script:
- npm install -g hexo-cli # Install Hexo itself
- npm install # Install Hexo modules and dependencies
- npm install hexo-renderer-pug # Install Butterfly pug
- npm install hexo-renderer-stylus # Install stylus renderer
# the 'pages' job will deploy and build your site to the 'public' path
pages:
stage: deploy
script:
- hexo clean # Hexo clean previous static site
- hexo generate # Hexo generate Static Site
artifacts:
paths:
- public
only:
- master # this job will affect only the 'master' branch
```
### GitLab-CI with AWS
In case if you want to deploy your website via AWS S3, here are the CI script:
```yaml
build website:
stage: build
# requiring the environment of NodeJS 4.2.2
image: node:latest
# add 'node_modules' to cache for speeding up builds
cache:
paths:
- node_modules/ # Node modules and dependencies
script:
- npm install -g hexo-cli # Install Hexo itself
- npm install # Install Hexo modules and dependencies
- hexo version
# the 'pages' job will deploy and build your site to the 'public' path
artifacts:
paths:
- public
deploy to s3:
stage: deploy
image:
name: amazon/aws-cli
entrypoint: [""]
script:
- hexo clean
- hexo generate # Hexo generate Static Site
- aws --version
- aws s3 rm s3://$S3_BUCKET --recursive
- aws s3 cp public s3://$S3_BUCKET --recursive
```
### GitHub Action
In case you want to deploy your website via GitHub Action, here are some of the code you can use:
```yaml
# workflow name
name: Hexo Blog CI
# master branch on push, auto run
on:
push:
branches:
- master
jobs:
build-hexo:
runs-on: ubuntu-latest
steps:
# check it to your workflow can access it
# from: https://github.com/actions/checkout
- name: Checkout Repository master branch
uses: actions/checkout@master
# from: https://github.com/actions/setup-node
- name: Setup Node.js 10.x
uses: actions/setup-node@master
with:
node-version: "10.x"
- name: Setup Hexo Dependencies
run: |
npm install hexo-cli -g
npm install
- name: Setup Deploy Private Key
env:
HEXO_DEPLOY_PRIVATE_KEY: ${{ secrets.HEXO_DEPLOY_PRIVATE_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$HEXO_DEPLOY_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Setup Git Infomation
run: |
git config --global user.name '名字'
git config --global user.email '邮件'
- name: Deploy Hexo
run: |
hexo clean
hexo generate
hexo deploy
```
### GitHub Action with FTP
```yaml
on: push
name: 🚀 Deploy website on push
jobs:
web-deploy:
name: 🎉 Deploy
runs-on: ubuntu-latest
steps:
- name: 🚚 Get latest code
uses: actions/checkout@v2
- name: 📂 Sync files
uses: SamKirkland/FTP-Deploy-Action@4.1.0
with:
server: ftp.samkirkland.com
username: myFtpUserName
password: ${{ secrets.ftp_password }}
port: 21
server-dir: # Setting the server-directory
```
### GitHub Action with Hexo and FTP
```yaml
# workflow name
name: Hexo Blog CI
# master branch on push, auto run
on:
push:
branches:
- master
jobs:
build-hexo:
runs-on: ubuntu-latest
steps:
# check it to your workflow can access it
# from: https://github.com/actions/checkout
- name: Checkout Repository master branch
uses: actions/checkout@master
# from: https://github.com/actions/setup-node
- name: Setup Node.js 10.x
uses: actions/setup-node@master
with:
node-version: "10.x"
- name: Setup Hexo Dependencies
run: |
npm install hexo-cli -g
npm install
- name: Setup Deploy Private Key
env:
HEXO_DEPLOY_PRIVATE_KEY: ${{ secrets.HEXO_DEPLOY_PRIVATE_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$HEXO_DEPLOY_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Setup Git Infomation
run: |
git config --global user.name 'Leon Xu'
git config --global user.email 'dcwinfield362@gmail.com'
- name: Deploy Hexo
run: |
hexo clean
hexo generate
hexo deploy
- name: Upload result from build job
uses: actions/upload-artifact@v2
with:
name: public
path: /public
deploy-to-website:
runs-on: ubuntu-latest
steps:
# check it to your workflow can access it
# from: https://github.com/actions/checkout
- name: Get latest code
uses: actions/checkout@v2
# from: https://github.com/actions/setup-node
- name: Sync files
uses: SamKirkland/FTP-Deploy-Action@4.1.0
with:
server: ftpupload.net
username: epiz_29134768
password: ${{ secrets.ftp_password }}
port: 21
server-dir: /home/vol3_1/epizy.com/epiz_29134768/test.hijklmno.gq/htdocs/
```
### Testing our builds before pushing content to the `master` branch
What if we want to test our builds in another branch before afecting `master`?
We'll just need to set a `test` job to do this for us:
<br>
```yaml
image: node:latest
cache:
paths:
- node_modules/
before_script:
- npm install -g hexo-cli
- npm install
# add a job called 'test'
test:
stage: test
script:
- hexo generate
except:
- master # the 'test' job will affect all branches expect 'master'
# the 'pages' job will deploy and build your site to the 'public' path
pages:
stage: deploy
script:
- hexo generate
artifacts:
paths:
- public
only:
- master # this job will affect only the 'master' branch
```
----
## Usage
_**Note:** we assume you have [Hexo 5][Hexo] installed, up and running locally._
- Fork, clone or download this project
- Install [Hexo Server][server] if you don't have it already: `npm install hexo-server --save`
- Configure Hexo [`_config.yml`] according to your project
- Navigate to the project folder (`cd path/to/project`)
- Run `hexo server`
### How to change Hexo version?
Modify [`package.json`]:
<br>
```json
{
"hexo": {
"version": "5.4.0"
}
}
```
----
## References
- NodeJS [Docs][node-docs]
- npm [Docs][npm-docs]
- Hexo [Docs][hexo-docs]
- Hexo [Themes]
----
## Enjoy!
[docker-lib]: https://hub.docker.com/u/library/
[Hexo]: https://hexo.io/
[Butterfly]: https://github.com/jerryc127/hexo-theme-butterfly
[hexo-docs]: https://hexo.io/docs/
[node]: http://nodejs.org/
[node-docs]: https://nodejs.org/en/docs/
[git]: http://git-scm.com/
[npm]: https://www.npmjs.com/
[npm-docs]: https://docs.npmjs.com/
[server]: https://hexo.io/docs/server.html#hexo-server
[SSG]: https://www.staticgen.com/
[Themes]: https://hexo.io/themes/
[lftp]: https://lftp.tech/
[`_config.yml`]: https://gitlab.com/leonxu260/hexo-butterfly/blob/master/_config.yml
[`.gitlab-ci.yml`]: https://gitlab.com/leonxu260/hexo-butterfly/blob/master/_config.yml
[`package.json`]: https://gitlab.com/leonxu260/hexo-butterfly/blob/master/package.json
# Leon的技术阁 (Leon's Tech Pavilion)
[![Pipeline Status](https://git.leonxu260.dev/Discharge7443/hexo-butterfly/badges/master/pipeline.svg)](https://git.leonxu260.dev/Discharge7443/hexo-butterfly/actions)
![Hexo Version](https://img.shields.io/badge/Hexo-8.1.2-blue.svg)
![Theme](https://img.shields.io/badge/Theme-Butterfly_5.7.2-ff69b4.svg)
## Description
Source repository for **Leon的技术阁** (Leon's Tech Pavilion), a personal Chinese-language
tech blog by Leon Xu. The site is generated with [Hexo](https://hexo.io/) using the
[Butterfly](https://github.com/jerryc127/hexo-theme-butterfly) theme, and every push to
`master` triggers a Gitea Actions pipeline that builds the static site and deploys it
over SSH to a self-hosted server.
**Live site:** <https://www.leonxu260.dev> (canonical `www` host, behind Cloudflare;
the apex `leonxu260.dev` 301-redirects to `www`; HTTPS everywhere via Let's Encrypt).
### Features
- Chinese-language blog (`zh-CN`) built on Hexo 8.1.2 and Butterfly 5.7.2
(installed as the `hexo-theme-butterfly` npm package — no vendored theme copy).
- Fully automated deploys: push to `master` and the site is rebuilt and live in seconds.
- Key-based rsync deploys — the server rejects password authentication by policy.
- Rich plugin set: `abbrlink` permalinks, sitemap + Baidu sitemap, Algolia search,
encrypted posts, word counts, lazy-loaded images, and Butterfly tag-plugin widgets.
- Site configuration in [`_config.yml`] and [`_config.butterfly.yml`]; dependencies in
[`package.json`].
## Installation
Requirements:
- **Node.js 22** (matches the CI environment)
- **yarn** (the repo ships a `yarn.lock`; there is no `package-lock.json`)
- git
Steps:
1. Clone the repository:
```bash
git clone https://git.leonxu260.dev/Discharge7443/hexo-butterfly.git
cd hexo-butterfly
```
2. Install dependencies:
```bash
yarn install
```
3. (Optional) Install the Hexo CLI globally for local preview commands:
```bash
npm install -g hexo-cli
```
### Forking the deploy setup
The CI/CD pipeline lives in [`.gitea/workflows/deploy.yml`]. To reuse it you need:
- A [Gitea](https://gitea.io) instance with Actions runners (`act_runner`)
- A repository secret named `DEPLOY_KEY` containing the **private** half of an SSH key
whose public half is in the target server's `authorized_keys`
- A webroot on the server to rsync into (the workflow syncs to
`root@<server>:/www/wwwroot/<domain>/`)
Note that the workflow pins the server's IP address on purpose: the site's domain is
Cloudflare-proxied, and Cloudflare does not proxy SSH, so the rsync step must talk to
the origin directly.
## Usage
Local development:
```bash
hexo server # live preview at http://localhost:4000
hexo generate # build the static site into public/
hexo clean # remove generated files and the Hexo cache
```
Deployment requires nothing beyond a push:
```bash
git add .
git commit -m "new post"
git push origin master
```
The [deploy workflow](.gitea/workflows/deploy.yml) then:
1. Checks out the repo and sets up Node 22
2. Installs `hexo-cli` + yarn and runs `yarn install --frozen-lockfile`
3. Runs `hexo generate`, producing ~171 files (~9 MB) in `public/`
4. Writes an SSH deploy key from the `DEPLOY_KEY` secret
5. `rsync -avz` over SSH (key-based only; the server rejects password auth) to
`root@69.164.253.99:/www/wwwroot/leonxu260.dev/`
Transfers are incremental — the first deploy took ~100 s; subsequent runs finish in
seconds. The workflow also supports manual dispatch from the Gitea Actions tab. The
server runs BT Panel (BTPanel) + nginx, which serves the synced `public/` output
directly as the webroot.
## Support
This is a personal site, but questions and corrections are welcome — open an issue at
<https://git.leonxu260.dev/Discharge7443/hexo-butterfly/issues>.
## Contributing
Content is personal, but fixes (broken links, config or CI improvements) are
appreciated. To work on it locally:
```bash
yarn install
hexo server # verify your changes at http://localhost:4000
hexo generate # confirm a clean build
```
Please keep changes compatible with Node 22 / yarn, and remember that any push to
`master` deploys to production.
## Authors and acknowledgment
- **Leon Xu** — site content, configuration, and deploy pipeline.
- [Hexo](https://hexo.io/) and its plugin authors, and
[Butterfly](https://github.com/jerryc127/hexo-theme-butterfly) (theme) — the
framework and design this blog is built on.
## License
Not specified — the repository contains no LICENSE file, and the site content is the
author's personal work.
## Project status
Active. Every push to `master` triggers an automated build and deploy. Recent
milestones:
- Migrated git hosts: abandoned gitlab.com → self-hosted Gitea (with Actions runners)
- Migrated deploy mechanism: SFTP (`hexo-deployer-sftp`) → key-based rsync over SSH
- Upgraded the stack: Hexo 6 → 8, Butterfly 4 → 5
[`_config.yml`]: https://git.leonxu260.dev/Discharge7443/hexo-butterfly/src/branch/master/_config.yml
[`_config.butterfly.yml`]: https://git.leonxu260.dev/Discharge7443/hexo-butterfly/src/branch/master/_config.butterfly.yml
[`package.json`]: https://git.leonxu260.dev/Discharge7443/hexo-butterfly/src/branch/master/package.json
[`.gitea/workflows/deploy.yml`]: https://git.leonxu260.dev/Discharge7443/hexo-butterfly/src/branch/master/.gitea/workflows/deploy.yml