Hexo+GitHub搭建个人博客

博客是记录成长与进步的最好工具

1 安装软件

安装git

1
$ sudo apt-get install git-core

安装Node.js

1
2
$ curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
$ sudo apt-get install -y nodejs

安装Hexo

1
$ npm install -g hexo-cli

新建工作空间

1
2
3
$ hexo init <folder>
$ cd <folder>
$ npm install

其中_config.yml文件配置网站信息; source存放用户资源数据; themes存放博客主题.

2 更换主题

优雅的主题能够给人带来美感和创作的源泉, 本博客采用的主题为Ayer. 可根据个人审美选择偏爱的主题.首先将主题文件下载到theme文件夹中

1
$ git clone https://github.com/Shen-Yu/hexo-theme-ayer.git themes/ayer

将工作空间根目录下的_config.yml中的theme值修改为ayer

1
theme: ayer

其中主题的细节配置可通过修改新下载主题ayer文件夹中的_config.yml文件, 详细内容可参阅ayer官方文档.

3 GitHub配置

生成GitHub的SSH Key

1
$ ssh-keygen -t rsa -C "email of github account"

复制 ~/.ssh/id_rsa.pub 文件中的内容, 将其粘贴到”GitHub->Setting->SSH and GPG Keys->New SSH key”中, 并新建以”liuhang0727.github.io”命名的仓库.

4 部署测试

安装hexo-deployer-git

1
$ npm install hexo-deployer-git --save

修改工作空间根目录下的_config.yml中的deploy值

1
2
3
4
deploy:
type: git
repo: git@github.com:liuhang0727/liuhang0727.github.io.git
branch: master

远程部署

1
2
3
$ hexo clean
$ hexo generate
$ hexo deploy

在浏览器中输入 https://liuhang0727.github.io 即可查看搭建的博客.

5 新建博客

可通过命令行新建文章

1
$ hexo new <模板> <文章名>

其中模板包括post, draft和page三类, 详细介绍可参阅官方文档. 新建的文件存放在source/_post/*.md, 可使用vscode进行Markdown文本编辑, Markdown语法可参考博客. 在完成创作后, 可发布部署

1
2
3
$ hexo clean 
$ hexo generate
$ hexo deploy

更多信息,请参阅Hexo官方文档.

  • 版权声明: 本博客所有文章均采用 Apache License 2.0 许可协议。转载请注明出处!
  • © 2020-2021 Hang Liu
  • Powered by Hexo Theme Ayer
  • PV: UV: