1.配置 Node.js 环境
1.1:下载 Node.js 安装文件,根据自己电脑的位数,选择下载32位或者64位的:http://nodejs.cn/download/,然后安装下载的文件,保持默认设置就好了,一路点 Next ,很快就安装完成了。
1.2:接着检查一下 Node 是否安装好,打开运行窗口,输入 cmd ,打开命令行:
1.3:在命令行分别输入以下命令:
node -v
npm -v
1.4:如果出现下图界面,则说明 node 安装正确。可以进入下一步了。
2.配置 Git 环境
2.1:去官网下载 Git 安装文件:https://git-scm.com/downloads接着进行安装,如下图,在 Windows Explorer integration 这一项及下边的两项都打上勾:
2.2:然后一直 Next 就可以了,安装完成后同样检查一下 Git 是否正确安装。
Github账户的注册和代码库的创建
3.1:Github帐号注册,打开链接:https://github.com,申请一个 Github 帐号;
3.2:注册好之后还需要确认邮箱,打开注册的邮箱,确认注册,然后进入下一步;
点击页面右上角自己的头像,点击下拉菜单的New repository,创建一个新的代码库:
3.3:代码库的名字最好与你的用户名相同,格式为 wangsai0806.github.io ,比如我的用户名是 wangsai0806,那我的代码库名即为 wangsai0806.github.io
3.4:创建成功后出现下图所示界面,点击右边的复制按钮,复制这个地址:
4.配置 Github pages
4.1:随便找一个目录,右击鼠标,选择Git Bash Here,打开一个类似命令行的界面,输入以下代码:
$ git clone https://github.com/username/username.github.io
clone 后面的链接即就是上一步复制的那个链接,比如我的就是下面的代码:
$ git clone https://github.com/wangsai0806/wangsai0806.github.io.git
4.2:然后输入 cd 你的代码库名 ,例如 cd wangsai0806.github.io ,也可以直接进入该目录下的一个名为 wangsai0806.github.io 的文件夹。
$ cd wangsai0806.github.io
4.3:创建index.html文件
$ echo “Hello World” > index.html
4.4:设置git的user.email和user.name
$ git config –global user.email “1069531172@qq.com”
$ git config –global user.name “wangsai0806”
4.5:提交文件
$ git add –all
$ git commit -m “Initial commit”
4.6:推送文件到github
$ git push -u origin master
可能会弹出以下界面让你登录,使用 Github 帐号登录即可。
4.7:此时你的 Github Pages 已经配置好了,打开 wangsai0806.github,io 这个网址就能看到你的博客了,wangsai0806 替换成你自己的用户名。
5.Hexo安装
5.1:创建 D:\notes\github\hexo 目录,鼠标右击打开 Git Bash Here,输入:
$ npm install hexo-cli -g
5.2:可能会看到一个 WARN,但是没关系的,进入下一步。
$ npm install hexo –save
$ npm install hexo-server –save
$ npm install hexo-admin –save
$ npm install hexo-generator-archive –save
$ npm install hexo-generator-feed –save
$ npm install hexo-generator-search –save
$ npm install hexo-generator-tag –save
$ npm install hexo-deployer-git –save
$ npm install hexo-generator-sitemap –save
5.3:等一段时间,他安装完之后检查一下是否安装成功,输入:
$ hexo -v
看到相关的版本信息则说明安装成功。
6.Hexo配置
6.1:初始化 Hexo,首先需要找一个目录,这个目录即就是你的博客的所有文件存放的目录,最好路径不要太深,我选择的是 D:\notes\github\blog 。在这个路径下打开 Git Bash Here ,输入代码:
$ hexo init
6.2:生成博客
$ hexo g
6.3:启动服务
$ hexo s
6.4:在浏览器打开 http://localhost:4000/ ,将会看到自己的 hexo 博客:
7.关联 Hexo 与 Github Page
7.1:配置Git个人信息
如果你之前已经配置好git个人信息,请跳过这一个步骤,直接来到步骤2
设置Git的user name和email:(如果是第一次的话)
$ git config –global user.name “wangsai0806”
$ git config –global user.email “1069531172@qq.com”
7.2:生成密钥
$ ssh-keygen -t rsa -C “1069531172@qq.com”
输入代码后一直按回车就好了,不用自己定义目录,生成的 ssh 会存放在 C:\Users\用户名.ssh 目录下,如果找不到 .ssh 目录,请在文件夹选项中显示隐藏的项目。
8.配置 SSH 密匙
8.1:进入 Github 网页,点击右上角自己的头像,选择 Settings :
8.2:配置 SSH and GPG keys ,点击 New SSH key:
8.3:用 txt 打开刚才生成的 Key,复制到下图所示区域,点击 Add SSH key:
9.配置 Deployment
9.1:打开博客目录下的站点配置文件 _config.yml ,比如我的博客目录是 D:\notes\github\blog,找到该目录下的 _config.yml。打开他,在最末尾找到 Deployment ,然后按照如下修改:
deploy:
type: git
repo: git@github.com:yourname/yourname.github.io.git
branch: master
上面的 wangsai0806 都要替换成自己的用户名,以我的为例:
deploy:
type: git
repo: git@github.com:wangsai0806/wangsai0806.github.io.git
branch: master
这样就配置好了,接下来就可以写博客了。
10.问题
10.1:权限问题《检查ssh秘钥》
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
10.2:$ hexo d ERROR Deployer not found: git
npm install --save hexo-deployer-git