搭建hexo博客

搭建hexo博客

准备环境

  1. Node.js下载安装

  2. Git下载安装

  3. 安装hexo,在git bash运行以下命令

    1
    npm install -g hexo-cli
  4. 初始化Hexo,git bash依次运行以下命令即可:

    1
    2
    3
    hexo init <folder>
    cd <folder>
    npm install
  5. 启动服务器,输入以下命令,运行即可

    1
    hexo server
  6. 浏览器访问网址:http://localhost:4000/,这时候你就可以看到自己的博客了

部署到GitHub

  1. 创建GitHubpages

  2. 添加SSH key,在git bash运行以下命令:

    1
    ssh-keygen -t rsa -C "你的邮箱地址"

    注意在需要你输入密码的时候可以回车忽略,不然每次发布到GitHub上都需要输入密码,很麻烦

  3. 修改站点目录下的_config.yml文件,文件末尾添加:

    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: git@github.com:<Github账号名称>/<Github账号名称>.github.io.git
    branch: master

    注意在每一个冒号后面都加上空格,不然会报错

  4. 推送到GithubPages。

    1
    2
    hexo g
    hexo d
  5. 浏览器访问https://<Github账号名称>.github.io/这时候你就可以看到自己的博客运行在GitHub上了