Hexo 6.x结合Next 8.x搭建(一)

Hexo配置

Next官方文档
里面啥都有,看完之后不需要再往下看,下面仅为个人搭建过程备份。

网站基础信息修改

_config.yml
1
2
3
4
5
6
7
8
# Site
title: Just Do IT
subtitle: 开心抄代码
description: 爱编码、爱做饭、爱你
keywords:
author: jackkke
language: zh-CN
timezone: Asia/Shanghai

站点url配置

Github 链接

文章链接短链支持插件安装
1
$ npm install hexo-abbrlink

注意:如果你的projectname非username.github.io形式, root则需要加上你的projectname

_config.yml
1
2
3
url: https://jackkke.github.io
root: /
permalink: posts/:year-:month-:day/:abbrlink/

跳过页面编译

使用腾讯云cdn加速需要以下配置

_config.yml
1
2
skip_render:
- verification.html

主题指定

Github 链接

移除默认主题,增加next主题
1
2
$ npm uninstall hexo-theme-landscape
$ npm install hexo-theme-next
_config.yml
1
theme: next
复制一份默认配置到根目录,并重命名
1
cp blog\node_modules\hexo-theme-next\_config.yml blog\_config.next.yml

部署

Github 链接

git部署
1
$ npm install hexo-deployer-git
_config.yml
1
2
3
4
5
6
7
deploy:
- type: git
repo: [email protected]:jackkke/jackkke.github.io.git
branch: master
- type: git
repo: [email protected]:jackkke/jackkke.git
branch: master

自动部署

Github 链接

  • HEXO_GITHUB_PRIVATE_KEY 这个是github和gitee的sshkey,需要添加到项目的secrets
  • GITEE_PASSWORD 这个是gitee的密码,gitee部署后需要手动更新,使用脚本进行自动部署”最后一公里”
  • 密钥添加链接https://github.com/jackkke/blog/settings/secrets/actions
blog\.github\workflows\main.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: CI Hexo Blog Deploy
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository master branch
uses: actions/checkout@v3
# from: https://github.com/actions/setup-node
- name: Setup Node.js 16.x
uses: actions/setup-node@master
with:
node-version: "16.x"
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
npm install hexo-cli -g
npm install
- name: Setup Deploy Private Key
env:
HEXO_GITHUB_PRIVATE_KEY: ${{ secrets.HEXO_GITHUB_PRIVATE_KEY }}
run: |
mkdir -p ~/.ssh/
echo "$HEXO_GITHUB_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-keyscan gitee.com >> ~/.ssh/known_hosts
- name: Setup Git Infomation
run: |
git config --global user.name 'jackkke'
git config --global user.email '[email protected]'

- name: Deploy Hexo
run: |
hexo clean
hexo generate
hexo deploy
- name: Build Gitee Pages
uses: yanglbme/gitee-pages-action@main
with:
gitee-username: jackkke
gitee-password: ${{ secrets.GITEE_PASSWORD }}
gitee-repo: jackkke
branch: master

本地搜索

Github 链接

搜索本地支持
1
$ npm install hexo-generator-searchdb
_config.yml
1
2
3
4
5
search:
path: search.xml
field: post
content: true
format: html

字数统计

Github 链接

字数统计、阅读时间统计
1
$ npm install hexo-word-counter
_config.yml
1
2
3
4
5
6
7
symbols_count_time:
symbols: true
time: true
total_symbols: true
total_time: true
awl: 2
wpm: 200

系列文章

Github 链接

系列文章
1
$ npm install hexo-post-series
_config.yml
1
2
3
4
post_series:
list_title: "系列文章"
open_in_new_tab: false
reverse_sort: false

网站压缩

Github 链接

文章压缩
1
$ npm install hexo-neat
_config.yml
1
neat_enable
系列文章