Hexo 博客搭建流程

Hexo 博客搭建总是遇到各种问题,在此重新记录一下搭建好 Hexo 博客的过程。

环境配置

需要提前安装的软件:

  • Nodejs
  • Git

NPM 设置镜像源:

查看现有源 npm config get registry

设置淘宝源:npm config set registry https://registry.npm.taobao.org

用新源更新一波:npm update

检测是否安装成功

1
2
3
git --version
node -v
npm -v

安装 Hexo

新建一个文件夹,如 FelixBlog

安装 Hexo

1
npm install hexo-cli -g

安装部署到 Git Page 的 Deployer

1
npm install hexo-deployer-git --save  

再新建一个文件夹叫Hexo,随后初始化hexo

1
hexo init

查看效果

1
2
hexo generate
hexo server

配置 SSH 密钥

在新建的文件夹子中(FelixBlog),使用下面的命令新建

1
ssh-keygen -t rsa -C "your email@example.com" 

随后,一路回车,直到完成后,复制到剪贴板上。

1
clip < ~/.ssh/id_rsa.pub

随后添加到GitHub或者Gitee

测试连通性

1
2
ssh -T git@github.com
ssh -T git@gitee.com

配置 Git 个人信息

1
2
git config --global user.name "此处填你的用户名"  
git config --global user.email "此处填你的邮箱"

修改配置文件

修改_config.yml文件,如下:

1
2
3
4
5
deploy:
- type: git
repository:
github: git@gitee.com:caijiyang/caijiyang.git
branch: master

设置主题(npm)

主题:Next:Gemini

Github 主页:https://github.com/next-theme/hexo-theme-next/blob/master/docs/zh-CN/README.md

安装主题

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

安装完成后,在 Hexo 配置文件中将theme设置为next

1
theme: next

配置主题

1
cp node_modules/hexo-theme-next/_config.yml _config.next.yml 

按照官网进行配置。

官网:https://theme-next.js.org/docs/getting-started/

更新主题

更新主题前,先阅读更新说明:https://github.com/next-theme/hexo-theme-next/releases

使用命令更新主题,每个月都有新的更新哦。

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

更新后使用 VSCode 即可对比更新文件。