二、Hexo+Github搭建自己的博客

版权声明:kanghu https://blog.csdn.net/weixin_40739280/article/details/81011276
  • 1.安装Node.js,配置环境变量(注意node版本,好多问题在于node版本,我用的v10.5.0)
  • 2.安装git环境配置git环境
  • 3.github新建仓库,格式为:账户名.github.io,需要勾选Initialize this repository with a README
  • 4.安装hexo
    新建文件夹,命令:npm install hexo -g,开始安装Hexo
    命令:hexo -v,检查是否安装成功
    命令:hexo init,初始化该文件夹(“Start blogging with Hexo!”表示初始化成功)
    命令:npm install,安装所需要的组件
    命令:hexo g,首次体验Hexo
    命令:hexo s,开启服务器,访问该网址,localhost:4000(默认端口4000)------假如遇到问题,可能端口被占用,可通过命令:“hexo server -p 端口号”改变端口
    
  • 5.将Hexo和Github联系(需要使用Git Bash)

    命令:git config --global user.name "git名字"
    命令:git config --global user.email "自己邮箱"
    命令:ssh-keygen -t rsa -C “自己邮箱”(注意:命令:cd ~/.ssh可以检查是否存在.ssh文件夹),连续三次回车,生成密钥
    输入eval "$(ssh-agent -s)",添加密钥到ssh-agent,再输入ssh-add ~/.ssh/id_rsa,添加生成的SSH key到ssh-agent
    登录github下settings,添加ssh
    命令:ssh -T [email protected],测试添加ssh是否成功(看到后面自己用户名说明成功)
    配置Deployment,在其文件夹中,找到_config.yml文件修改deploy,下面有三个子属性,type、repository、branch,repository输入自己git上项目链接
    
  • 6.新建博客,命令:hexo new post “博客名”

  • 7.安装拓展,命令:npm install hexo-deployer-git –save
  • 8.生成的文章在source/_posts中,编辑好之后,命令:hexo d -g,生成以及部署,成功后访问http://用户名.github.io,即可看到效果

猜你喜欢

转载自blog.csdn.net/weixin_40739280/article/details/81011276