hexo安装及next主题个人配置

本篇内容纯粹为了个人安装方便,并非完整的安装教程。因为太喜欢装系统,所以hexo也要不断安装,写下这篇之后希望可以加速安装时间,不用再到处查看文档。

Hexo安装

安装Node.js

Linux(DEB/RPM-based):从 NodeSource 安装
Ubuntu:

1
2
curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt install -y nodejs

安装git

Ubuntu

1
sudo apt install git

安装Hexo

1
npm install -g hexo-cli

建立网站

1
2
3
hexo init <folder> #建立文件夹并初始化
cd <folder>
npm install

新建文件夹目录如下

1
2
3
4
5
6
7
8
.  
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes

如果非首次安装,在之前备份的文件内,把scaffoldspublic文件夹、_config.yml_config.next.yml文件拷贝到新建立的网站文件夹内相应位置。

配置

_config.yml中修改网站配置

_config.next.yml中配置next主题

next主题安装及配置

安装

1
2
cd hexo-site
npm install hexo-theme-next

安装后,在系统配置文件_config.yml中设置

1
theme: next

配置

next官方现不推荐在主题目录下修改任何文件,目的是为了方便升级,这种做法很好。那么,现在需要复制一份配置文件进行编辑,根据官方文档 ,有多种方式,我选择第一种,方式如下:

1、在根目录创建一个配置文件
1
touch _config.next.yml
2、从主题目录复制配置文件到根目录
1
2
# Installed through npm
cp node_modules/hexo-theme-next/_config.yml _config.next.yml

我至今不明白此处第一步意义何在,因为第二步复制的同名文件会直接覆盖第一步建立的空文件。

然后,所有的配置都在复制到根目录的这个_config.next.yml中进行。

实际上,具体的配置文件可以直接复制之前备份的那个文件,通用。但是,因为有些依赖没有安装,所以导致运行hexo g 的时候总是报错,这也正是我写这篇纪录最大的原因。

个人使用的第三方插件需要安装这几个依赖:

字数统计显示(Post Wordcount)

Install hexo-word-counter by executing the following command in site root dir:

1
2
npm install hexo-word-counter  
hexo clean

然后在_config.next.yml 中把相应参数设置为 true
此处还需要在hexo配置文件_config.yml 中做相应设置,个人配置如下:

1
2
3
4
5
6
7
8
9
symbols_count_time:
symbols: true
time: true
total_symbols: true
total_time: true
exclude_codeblock: false
awl: 3
wpm: 275
suffix: "mins."

Install hexo-related-posts by executing the following command in site root dir:

1
2
npm install hexo-related-posts  
hexo clean

本地搜索(Local Search

Install hexo-generator-searchdb by executing the following command in site root dir:

1
npm install hexo-generator-searchdb

根据官方文档在hexo配置文件和next配置文件中做相应设置

上传到GitHub的补充设置

前面在安装好已经设置好git和GitHub,需要注意现在GitHub授权不要用token方式,太麻烦,可以直接采用GitHub CLI的方式进行认证。

想要使hexo d 成功运行,需要

1、在`_config.yml` 中添加以下内容
1
2
3
4
deploy: 
type: 'git'
repo: 'url'
branch: 'master'
2、安装相应插件
1
npm install hexo-deployer-git --save

有需要再完善。