安装hexo
- 安装Node.js。
- 使用npm安装hexo-cli。
- 初始化Hexo博客。
- 安装node.js依赖包。
设置git仓库
推送源码
1 2 3 4 5 6 7 8 9 10 11
| git init
git config user.name "you" git config user.email "you@users.noreply.github.com"
git remote add origin git@github.com:you/your_repo.git
git add . git commit -m "Initial commit" git branch -M main git push -u origin main
|
创建Token
- 在GitHub Settings–>Developer settings–>Personal access tokens–>Tokens (classic)–>Generate new tokens (classic)创建一个token用于Github Action。
- Note可命名为
hexo_token,配置中勾选repo和workflow后生成token。
- 将token复制到仓库设置–>Secrets and variables–>Actions–>Repository secrets。
修改_config.yml配置deploy
1 2 3 4
| deploy: type: git repo: git@github.com:you/you.github.io.git branch: gh-pages
|
配置Github Action
- 在
\.github新增workflows\deploy.yml,内容如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| name: Deploy Hexo to GitHub Pages
on: push: branches: - main # 当推送到 main 分支时触发
jobs: build: runs-on: ubuntu-latest
steps: - name: Checkout repository uses: actions/checkout@v2 with: submodules: false # 禁用子模块检查
- name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '24'
- name: Install Dependencies run: npm install
- name: Install Hexo Git Deployer run: | npm install hexo-deployer-git --save npm install hexo-cli -g
- name: Clean and Generate Static Files run: | hexo clean hexo generate
- name: Configure Git run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Deploy to GitHub Pages env: GH_TOKEN: ${{ secrets.hexo_token }} run: | cd public/ git init git add -A git commit -m "Create by workflows" git remote add origin https://${{ secrets.hexo_token }}@github.com/your/your-repo.git git push origin HEAD:gh-pages -f
|
- node-version需版本一直,
node --version查看版本。
- 安装Icarus
1
| npm install -S hexo-theme-icarus hexo-renderer-inferno
|
安装完成后等一会生成_config.icarus.yml文件
2. 配置为Icarus主题
1
| hexo config theme icarus
|
开始写作
新建文章
1
| hexo new [layout] <title>
|
启动 Hexo 本地服务器
清理 Hexo 缓存和静态文件