Github pages和Hexo搭建自己的博客

电脑环境是Windows,安装好git后,所有搭建操作均在git bash内完成

1.需要安装git, node.js, npm

注:第一次安装Git会让配置user信息

$git config --global user.name "yourname"   #(yourname是git的用户名)
$git config --global user.email "youremail")

2.使用npm安装hexo: npm install -g hexo

3.创建hexo文件夹,并单击鼠标右键选择 Git bash:(我的创建路径是:E:\hexo)

4.在刚刚打开的git bash命令框中操作:

$hexo init 		#hexo 会自动创建网站所需要的文件
$npm install 	#安装依赖包
$hexo generate  # 等价于hexo g
$hexo server 	#现在可以用127.0.0.1:4000访问hexo默认的hello world界面,等价于hexo s

5.部署到github (https://github.com/),

  • 首先注册登录,然后创建页面仓库,Repository name 命名必须是 youname.github.io ,(youname 就是你注册时候用的name)
  • ssh-keygen -t rsa -C "email" #生成ssh密钥,按三次回车键,密码为空,这边会生成id_rsa和_rsa.pub文件,打开id_rsa.pub,复制全文添加到GitHub 的Add SSH key中。
  • 最后可以验证一下ssh -T git@github.com,看出现的是不是Hi "Yourname"如果出现了你的github用户名,则成功了

6.下载Hexo主题

  • $git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia #下载hexo的yilia 模板到自己的文件目录下

  • 打开项目目录下的_config.yml文件,更改theme:yilia

    ▲注意: _config.yml文件中配置时:后面都要加空格,与:隔开

7.开启评论功能:使用gitment

$npm install gitment --save #安装gitment

然后在 https://github.com/settings/applications/new 进行注册,获取Client ID和Client Secret

打开themes/yilia目录下的_config.yml文件进行修改并保存:

再次生成网站,提交网站:hexo d -g就可以输入网址:https://yourname.github.io打开你的博客了

posted @ 2018-08-31 19:34  南邮果粒橙  阅读(138)  评论(0编辑  收藏  举报