毕少侠也在江湖

快速搭建Hexo-blog指南

Hexo快速开始教程

快速搭建hexo博客的步骤如下:

  1. 安装Nodejs https://nodejs.org/zh-cn
  2. 安装Git, https://git-scm.com/
  3. 安装Hexo, https://hexo.io/zh-cn/index.html
  4. 初始化Hexo
  5. 选择主题
  6. 发布文章

1 前置环境

  • 安装Node.js
  • 安装Git
  • 安装Hexo

2 Hexo安装与配置

  1. 初始化站点 hexo init <folder>
  2. 进入个目录 cd folder
  3. 新建文章 hexo new <title>
  4. 启动Hexo站点 hexo clean && hexo g && hexo s

2.1 上传到github

3 安装主题并启动

hexo博客地址

使用 Hexo主题 hexo-theme-anzhiyu
文档地址:https://anzhiy.cn/tags/AnZhiYu/

配置地址:传送地址

可参考修改,部分都加入中文注释

4 Hexo自动部署Action

 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: 自动发布 hexo-deploay
# 触发条件:在 push 到 master 分支后触发
on:
  push:
    branches: 
      - master  # 可以添加多个分支

env:
  TZ: Asia/Shanghai

jobs:
  blog-cicd:
    name: Hexo blog build & deploy
    runs-on: ubuntu-latest # 使用最新的 Ubuntu 系统作为编译部署的环境

    steps:
    - name: Checkout codes
      uses: actions/checkout@v3
      with:
        submodules: true # 加载子模块,避免初始化过程中的额外加载。

    - name: Setup node
      # 设置 node.js 环境
      uses: actions/setup-node@v1
      with:
        node-version: '16.x'

    # 下载网站源码
    - name: Cache node modules
      # 设置包缓存目录,避免每次下载
      uses: actions/cache@v1
      with:
        path: ~/.npm
        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

    # 安装依赖
    - name: Install hexo dependencies
      # 下载 hexo-cli 脚手架及相关安装包
      run: |
        npm install -g hexo-cli
        npm install --no-fund
        npm install hexo-renderer-pug hexo-renderer-stylus --save
        npm install hexo-generator-search --save
        npm ls --depth 0        

    # hexo 编译生成网站
    - name: Generate files
      # 编译 markdown 文件
      run: |
        hexo clean
        hexo generate        

    # 自动发布到当前仓库的gh-pages分支,如需部署到其它仓库的,参考下面文档修改配置即可
    # 更多高级用法查看文档,https://github.com/peaceiris/actions-gh-pages
    - name: Deploy
      uses: peaceiris/actions-gh-pages@v3
      with:
        # 1.如何生成 github_token,github主页,Settings / Developer settings / Personal access tokens (classic)
        # 2.github_token 在 仓库 Settings,Actions secrets and variables,设置
        github_token: ${{ secrets.ACCESS_TOKEN }}
        publish_dir: ./public

        # Deploy to external repository external_repository
        # 发布到其他仓库的配置,注意必须使用deploy_key,获取和设置方法同上。
        #deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        #external_repository: username/external-repository
        #publish_branch: your-branch  # default: gh-pages
        #publish_dir: ./public


        # 以下配置可忽悠,测试功能
        user_name: 'github-actions[bot]'
        user_email: 'github-actions[bot]@users.noreply.github.com'
        commit_message: ${{ github.event.head_commit.message }}
        #full_commit_message: ${{ github.event.head_commit.message }}
        tag_name: ${{ steps.prepare_tag.outputs.DEPLOY_TAG_NAME }}
        tag_message: 'Deployment ${{ github.ref_name }}'
        #cname: github.com

相关内容

Buy me a coffee
geekswg 支付宝支付宝
geekswg 微信微信
0%