Hexo

  1. 安装Git和Node.js
  2. 安装hexo
  3. 创建hexo文件夹
  4. 本地查看
  5. 注册Github账号
  6. 设置
  7. 设置 SSH
  8. 部署
  9. 解决问题

用了一段时间farbox,嫌丑,试着建了一个hexo
换电脑之后又部署了一下,就写一篇博客吧
优点:免费,可配置性高
缺点:写文章、上传比较麻烦

官网

安装Git和Node.js

下载msysgit以及node.js

由于众所周知的原因,从上面的链接下载git for windows最好挂上一个代理,否则下载速度十分缓慢。也可以参考这个页面,收录了存储于百度云的下载地址。 ——摘自官网

安装hexo

在任意位置点击鼠标右键,选择Git bash

1
$ npm install -g hexo

创建hexo文件夹

在某一个盘里建一个文件夹(如H:\Hexo),在文件夹里点击鼠标右键,选择Git bash,Hexo 即会自动在目标文件夹建立网站所需要的所有文件。
或者打开Git bash然后输入cd /h/Hexo进入也可以。

1
2
$ hexo init
$ npm install

本地查看

现在我们已经搭建起本地的hexo博客了,执行以下命令(在H:),然后到浏览器输入localhost:4000看看。

1
2
$ hexo generate
$ hexo server

好了,至此,本地博客已经搭建起来了,只是本地哦,别人看不到的。下面,我们要部署到Github。

注册Github账号

Github上注册,在自己Github主页右下角,创建一个新的repository。
注意repository和账号名字必须一样。比如我的Github账号是xxx,那么我应该创建的repository名字应该是xxx.github.io。

设置

编辑_config.yml(在文件夹里)。

1
2
3
4
deploy:
type: git
repo: ssh://git@github.com/xxx/xxx.github.io.git
branch: master

设置 SSH

打开Git Bash
1.检查现有的SSH key

1
2
$ ls -al ~/.ssh
//检查是否有SSH key,没有则开始设置

2.生成新的SSH key

1
2
3
4
5
6
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Generating public/private rsa key pair.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): 回车
Enter passphrase (empty for no passphrase): 回车
Enter same passphrase again: 回车
//把SSH密码设成了回车

3.将新创建(或现有的)SSH密钥添加到ssh-agent

1
2
3
4
$ eval "$(ssh-agent -s)"
//后台启动ssh-agent
$ ssh-add ~/.ssh/id_rsa
//将SSH key添加到ssh-agent

4.添加新的SSH密钥到你的GitHub帐户

1
2
$ clip < ~/.ssh/id_rsa.pub
//复制id_rsa.pub文件的内容到剪贴板

在Github任何页面的右上角,单击个人资料照片,然后点击setting
在用户设置栏中,点击SSH keys
点击New SSH key
粘贴key插入“Key”字段中;
点击Add SSH key

5.测试你的SSH连接

1
2
3
4
5
6
7
$ SSH -T git@github.com 
//尝试ssh到GitHub
The authenticity of host 'github.com' can't be established.
RSA key fingerprint is xxx.
Are you sure you want to continue connecting (yes/no)? 输入yes
Hi *username*! You've successfully authenticated, but GitHub does not
provide shell access.

部署

以后每次更改后都要部署才能在网页上显示

1
2
hexo g
hexo d

或者(Menci教的Orz)

1
hexo g -d

解决问题

配置hexo时出现了一些奇怪的东西

1:

1
2
$ hexo g
sh: hexo: command not found

解决方法:
添加环境变量(控制面板>系统和安全>系统>高级系统设置>环境变量)
C:\Users\用户名\node_modules\hexo\bin添加到用户变量的PATH变量后面
注意千万不要把原来的删掉,用";"把它们隔起来,不然你会死的很惨

2:

1
2
$ hexo d
ERROR Deployer not found: git

解决方法:

1
$ npm install hexo-deployer-git --save

3:

1
warning: LF will be replaced by CRLF in ~~~

解决方法:

1
$ git config --global core.autocrlf false

4:

1
2
3
4
5
6
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.

解决方法:

1
2
$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"

5:其他请百度Google,应该都能解决

之后的hexo d是这样的

1
2
3
4
5
6
7
8
9
10
$ hexo d
INFO Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
INFO Copying files from extend dirs...
On branch master
nothing to commit, working tree clean
Branch master set up to track remote branch master from ssh://git@github.com/xxx.
Everything up-to-date
INFO Deploy done: git

参考Zippera's blog