Hexo+github+NexT > 更漂亮的博客

需要的环境

  • git
  • node
  • hexo
  • NexT

搭建步骤

如果电脑没有git、node环境

1
2
$ sudo apt-get install git-core   // 安装Git
$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh //安装 Node.js

安装Hexo

$ mkdir hexoBlog
$ npm install hexo-cli -g

初始化Hexo

1
2
3
$ mkdir blog
$ cd blog
$ hexo init

生成静态网站

1
$ hexo g    // Generat

本地启动测试

1
$ hexo s    // server,打开(http://localhost:4000)进行本地测试

创建GitHub仓库

仓库名称:xxx.github.io // xxx是GitHub账户名称

配置Hexo

打开根目录的_config.yml文件,如下配置:

1
2
3
4
deploy:
type: git
repository: https://github.com/xxx/xxx.github.io.git
branch: master

安装git部署工具

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

部署到GitHub

1
$ hexo d

绑定域名

  • 在根目录下的source文件夹内创建CNAME文件,在文件内写上要绑定的域名。
  • 给域名添加如下2个解析:
    1
    2
    主机记录:@    记录类型: A    记录值:192.30.252.153     TTL: 10分钟
    主机记录:www 记录类型: A 记录值:192.30.252.154 TTL: 10分钟
  • 生成静态网站并部署即可
    1
    2
    $ hexo g
    $ hexo d

安装NexT

  • 安装
    1
    $ git clone https://github.com/iissnan/hexo-theme-next themes/next
  • 启用
    打开根目录的_config.yml文件,如下配置:
    1
    $ theme: next
  • 本地测试
    1
    $ hexo s -debug
  • 部署
    1
    2
    $ hexo g
    $ hexo d
  • Tips
    切换主题之后验证之前可以清除hexo缓存:$ hexo clean,或者清除浏览器缓存。

发布文章

1
2
3
4
$ hexo new [layout] "post-name"
$ hexo g // 生成静态文件。
$ hexo s // 在本地预览效果。
$ hexo d // 同步到github。