前置准备:配置好Node.js和Git,并注册一个GitHub账号。
创建本地文件
使用npm包管理器全局安装Hexo:
1  | npm install hexo -g  | 
找到一个合适的目录,创建一个空文件夹,接着在这个文件夹内创建博客文件:
1  | cd D:\Koorye.github.io  | 
接下来,将markdown文件放在source/_posts目录中,就会显示到博客上。
部署到GitHub
新建仓库
新建一个公共仓库,名称必须为xxx.github.io,这将是你博客的域名。
配置本地文件
接下来对本地博客文件的_config.yml进行配置,将仓库路径写到repository上:
1  | # Deployment  | 
配置Git
创建账号
1  | git config --global user.name "username" // username替换成你的用户名  | 
创建SSH密钥
检查C:\Users\你的用户名文件夹中是否有.ssh文件夹,没有则用如下命令新建一个密钥:
1  | ssh-keygen -t rsa -C "你的邮箱地址"  | 
之后会生成如下文件:
连接到GitHub
点击GitHub右上角的个人头像,找到Settings,然后点击左侧栏的SSH and GPG keys.
点击New SSH key,将生成的id_rsa.pub中内容复制到Key中,Title随意:
创建好的SSH Key:
测试连接
1  | ssh git@github.com  | 
返回如下提示即配置成功:
1  | PS C:\Users\a1311> ssh git@github.com  | 
hexo上传
首先了解一下hexo的命令行:
1  | hexo init // 初始化一个博客  | 
了解一下命令后,我们通常使用clean(清理缓存)+generate(生成文件)+deploy(部署)上传博客:
1  | hexo clean  | 
返回如下,博客就部署完成: 1
2
3
4
5
6
7
8
9
10
11
12
13PS D:\Koorye.github.io> hexo d
INFO  Deploying: git
INFO  Clearing .deploy_git folder...
INFO  Copying files from public folder...
INFO  Copying files from extend dirs...
...
warning: LF will be replaced by CRLF in tags/神经网络/index.html.
The file will have its original line endings in your working directory
On branch master
Everything up-to-date
Branch 'master' set up to track remote branch 'master' from 'git@github.com:Koorye/Koorye.github.io.git'.
检查一下github仓库,可以看到文件已经上传:
此时,我们便可以通过访问https://Koorye.github.io看到自己的博客啦,部署略有延迟,请等待几分钟再查看。
使用Next主题
下载主题
原版的主题比较简单,而且缺少很多功能,相比之下,next主题是很好的选择。
使用git clone下载主题:
1  | git clone https://github.com/iissnan/hexo-theme-next themes/next  | 
下载之后,博客文件themes目录中就会有next目录。
修改配置文件_config.yml的theme为next:
1  | # Extensions  | 
之后,重新编译打开网页,next就改变啦:
1  | hexo clean  | 
访问http://localhost:4000,这里笔者已经修改了很多配置才有这样的效果:
关于next主题的各种配置,本文不再赘述。
安装插件
这里举例安装live2d插件,其他插件的安装大同小异:
这里我们安装这只叫hijiki的黑猫:
按照官网的步骤,先安装插件:
1  | npm install --save hexo-helper-live2d  | 
然后配置_config.yml,加入以下内容,自行设定width和height:
1  | live2d:  | 
再次编译打开网页,hijiki就会在屏幕的右下角啦。
关于markdown书写格式
hexo的markdown开头需要写明一些配置,例子如下,这样文章才能正确显示标题、日期等信息:
1  | ---  |