真的是手把手教你如何Hexo一个你自己的github网站
结合本人的个人经验,自己也摸索很久了,网上的资源很多,翻阅了很多资料,但是感觉不全。原谅作者是一个菜鸟。但是呢, 你摸索久了,自然而然也会总结出经验。好了废话不多,先看看作者的个人网站。DaiSuke。现在结合自己操作流程,你们也来操作一下吧。
工具:Mac
1.安装brew(可以去官网看看Homebrew)
终端输入命令:
ruby -e"$(curl -fsSL --insecurehttps://raw.githubusercontent.com/Homebrew/install/master/install)"

注意:中间执行的时候会有提示,回车和输入电脑密码
2.安装git
终端输入命令:
brew install git


注意:红色框框的是git安装的路径

3.安装Node.js
终端输入命令:
brew install node


注意:红色框框的是node安装的路径
查看是否安装成功,显示是v5.11.0版本
终端输入命令:
node –v

4.创建SSH key
在终端输入:
ssh-keygen -t rsa -b 4096 -C "github的邮箱(即你的github账号)"
当然,如果你没有github账号,请移步github注册,注册账号大家都会吧。
在执行的时候,需要以下操作:
回车-输入github账号密码—再次输入(不是电脑锁屏密码)

5.添加密钥到你的github中
进入你的github主页, 点击头像--设置

选择SSH and GPG keys --> New SSH key

接下来就是把刚才的生成的密钥复制到这里了。
有两种方法:
1:在终端输入:
pbcopy < ~/.ssh/id_rsa.pub
使用命令把id_rsa.pub文件的内容copy下来
然后粘贴到下面的key中,title随便写
2:从目录进去找到id_rsa.pub文件
一般都在这里:/Users/用户名/.ssh/。这个路径,可以在你生成密钥的时候在终端看到。

打开id_rsa.pub,把里面的东西复制下来

添加SSH keys

完成时是这样的

6.安装Hexo
不想全局安装的话,就新建一个文件夹。比如我在桌面建一个GithubBlog文件夹,这里专门存放我的博客以及网站样式等
比如:

在终端进入这个文件夹

然后在终端输入:
sudo npm install –g hexo
正在安装…期间会提示你输入密码



在终端输入:
hexo init
当然你也可以输入:
hexo init <安装的目录>


一切差不多准备好了。
在终端输入:
hexo generate
目的:生成静态页面

在终端输入:
hexo server

打开浏览器,输入你的本地网站的地址:http://localhost:4000
在浏览器上访问以下

到这里你是不是很激动啊?反正当时我操作到这里就很happy。
没错,这只是本地的一个网站而已,想让更多人看到,那就把它部署到github那里吧。
7.在github创建仓库
(这个就是把你的本地文件上传到开源的github中)
首先,进入github主页



8.部署到github中
进入安装hexo的目录,打开_config.yml文件


打开_config.yml文件后找到,然后修改
deploy:
# git类型
type:git
# 仓库地址:
repository: git@github.com:DaisukeZJY/daisukezjy.github.comm.git
# 分支:主分支
branch:master

保存文件
9.克隆主题
我找的是nexT这个,其他你可以google以下hexo主题,很多主题
1、在_config.yml找到这里,theme:填写你的主题,保存文件

2、在终端输入你要克隆主题的地址
git clone https://github.com/klugjo/hexo-theme-next.git themes/next
克隆完成之后开始部署了
10.最终操作
记住:每次修改_config.yml或其他,都要更新,重新部署
两个步骤:
hexo g//更新
hexo d//部署

11.终于可以访问网站了
打开浏览器输入:
https://daisukezjy.github.io
12.问题
部署的时候出现错误:
ERRORDeployer not found:github
解决方法,在终端输入:
npm installhexo-deployer-git –save
然后在_config.yml把github改为git

13.题外话
现在我用的nexT,里面集成很多插件和样式,具体使用修改,参考官方文档nexT