github博客搭建

github博客搭建

十一月 20, 2019

本文主要解决如何在github上搭建hexo博客。主要涉及到两部分内容:

  1. 搭建博客流程及相关工具
  2. 书写博客流程及相关方法

github博客搭建

  1. 注册github账号,网址https://github.com
  2. 创建博客仓库,仓库名称必须为username.github.io,这里的username为你的用户名,将来博客访问地址https://username.github.io
  3. 配置本机ssh免密访问github
    1
    ssh-keygen -t rsa
    将用户家目录下的.ssh/id_rsa.pub文件内容复制到github中个人设置–>SSH and GPG keys–>New SSH key
    测试方法如下则表示配成功
    1
    2
    $ ssh -T git@github.com 
    You've successfully authenticated, but GitHub does not provide shell access.
  4. 配置git全局信息
    1
    2
    $ git config --global user.name "username"// 你的github用户名,非昵称
    $ git config --global user.email "user@qq.com"// 填写你的github注册邮箱

hexo博客书写

  1. 本地安装nodejs,npm
  2. 安装hexo
    1
    2
    3
    npm install -g hexo
    #hexo部署github插件
    npm install hexo-deployer-git --save
  3. 初始化博客
    1
    2
    3
    4
    5
    6
    #初始化博客
    hexo init
    #生成文件
    hexo g
    #启动服务器
    hexo s
  4. 上传博客到github
    修改_config.yml文件
    1
    2
    3
    4
    deploy:
    type: git
    repo: git@github.com:usrname/usrname.github.io.git
    branch: master
  5. 写文章
    1
    2
    3
    4
    5
    6
    #创建文章
    hexo new postname
    #生成文章
    hexo clean
    #上传文章
    hexo d -g
  6. 更换主题
    下载hexo主题,修改_config.yml文件