使用hxo和github搭建blog步骤

  1. 安装
    安装Node
    brew install node
    该命令执行后,自动装好node和npm
    安装git
    brew install git
    安装hexo
    npm install -g hexo

  2. 创建Hexo目录
    mkdir ~/Works/blog
    cd ~/Works/blog
    hexo init
    Hexo 会自动在~/Works/blog目录下建立网站所需要的所有文件

  3. 安装依赖包
    npm install

  4. 本地查看
    hexo generate
    hexo server
    到浏览器输入localhost:4000可以看到网站。

  5. 注册github(已注册过了此处略)

  6. 创建 Repository
    创建的时候注意Repository的名字。比如我的Github账号是zrainx,那么我应该创建的Repository的名字是:zrainx.github.io

  7. 编辑_config.yml文件
    vi _config.yml
    编辑并保存:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: http://zrainx.github.io/
    root: /
    permalink: :year/:month/:day/:title/
    permalink_defaults:
    ........
    ........
    ........
    # Deployment
    ## Docs: http://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: https://github.com/zrainx/zrainx.github.io.git
  8. 部署
    hexo generate
    hexo deploy
    用浏览器就可以访问http://zrainx.github.io 了 :)

  9. 搭建过程中遇到的问题

  • 部署的时候执行:hexo deploy 命令行没有任何输出,也没有错误。
    解决办法
    在部署的_config.yml文件中,找到deploy:标签,在每个冒号后面必须要空格,否则就会出现上述问题。
  • 部署提示找不到 gitERROR Deployer not found: git
    解决办法
    在Hexo 3.0版本后deploy git 被分开的,所以需要安装,安装命令如下:
    npm install hexo-deployer-git --save ,安装好后在尝试一下就ok

  • 部署提示email邮箱不正确
    解决办法
    git config --global user.email "github注册邮箱"
    git config --global user.name "用户名"