Use github to build free hexo blog

Something to be prepared

System installation Node.js , Git , sign up for a GitHub account


 

First, the local installation hexo

Open Git Bash, enter the command:

npm install hexo-cli -g

After installation is complete, using the command hexo init / c / blog deployment HEXO, wherein / c / blog means designated blog directory C drive, can modify.

If, after execution Tip: command not found

The hexo environment variables can be added to the system.

After completion of the command, hexo already deployed locally, use the command to start hexo hexo server locally, then start the visit  http: // localhost: 4000  to see the effect, if not wrong, then, should appear the following figure interface:

/ **** (After my problems! When accessing the local discovery was rejected ??? (* ¯︿¯) found git not start hexo? No! You did not operate in the blog directory, crying Liao) * ** /

hexo so successful local start   

******************************************************************************************************************************************************************************************

 

 

 


 

Second, configure and deploy

Now that we have a good set up in the local hexo, in order to hexo deployed to GitHub pages, we need a series of configuration.

1, the configuration Git

git config --global user.email "GitHub your registered email address."

git config --global user.name "your GitHub username"

Then generate your key

ssh-keygen -t rsa -C “你的GitHub邮箱”

执行之后直接三次回车即可            注意ssh与-keygen中间没有空格,否则会报错(不要问我怎么知道的( ̄﹏ ̄;))

然后在你的用户目录会出现一个 .ssh 文件夹,具体路径为C:\Users\用户名\.ssh,打开该目录下的 id_rsa.pub 文件,该文件为公钥,将其内容复制到GitHub,如下图操作:

 

 然后

 

保存之后测试是否成功      ssh -T [email protected]

执行命令之后如下图如果终端出现 Hi!You’ve successfully authenticated 则证明环境配置成功。


 

2、建立仓库

 我们需要在GitHub上建立一个仓库用来存放hexo的文件,仓库的名称必须为 你的用户名.github.io ,其他的仓库名均无法使用


3、在GitHub上部署hexo

经过前两步的操作,我们已经完成了准备工作,已经可以准备在GitHub上部署hexo了,在这之前我们需要将本地hexo和GitHub仓库建立联系。

修改blog文件夹下的 _config.yml 文件,直接拉动最底部,按照自己的博客修改deploy的内容

 

修改完成之后我们需要安装一个插件,有了这个插件我们才能将hexo部署到GitHub pages。

执行以下命令:

npm install hexo-deployer-git -g

安装完成之后即可开始部署到GitHub

执行以下命令

hexo clean # 清除缓存文件

hexo d -g #生成静态文件并部署到GitHub

执行完成之后,静等缓存同步,不出意外的话你已经可以通过 https://你的用户名.github.io 访问到你的博客啦。(当然你出了意外的话还是要百度一哈啥问题/逃)


 

三:绑定域名与开启https

为了美观以及方便访问,我们可以给GitHub pages绑定个人域名,在经过几次更新之后,绑定域名的操作已经很人性化了。

1、创建CNAME文件

在source文件夹下创建CNAME文件,文件内容为你要绑定的域名。

然后执行命令

hexo d -g


2、设置域名解析

在你的域名服务商处设置两个CNAME解析,分别为www和@,如下图:

 

保存之后静等解析生效,大概需要10分钟左右。

3、开启https

当你解析域名生效之后,即可通过域名访问GitHub pages,但是你会发现访问并不是https,这是因为你的域名没有与之对应的证书,不过不用担心,GitHub已经准备了免费的证书供你使用。

找到你github的博客库中的设置,最下面有强制使用https的开关,勾选上就好了。

注意:有些情况下 强制https 开关会显示不可用,这是因为你的证书还未准备好,稍等片刻即可。

Guess you like

Origin www.cnblogs.com/threesoil/p/10669876.html