博主第一个Blog就是通过hexo搭建出来的,大概用了两天,期间碰到太多的问题了,基本上所有的错误都出现了= =搭建完后顺便写一个教程吧~
博主使用的平台是windows 10。
Hexo静态博客的准备工作
GitHub部分
注册就不多说了,如果注册后不想用那个ID了账号是可以删除的哦
首先新建一个profile

然后格式一定是你的ID.github.io

之后点击绿色的create repository创建
另外推荐下载GitHub for windows要是会用Git工具的话也可以不用
这样你的Blog就建立好了,但是什么都木有
**关于GitHub for windows的使用方法 **
官方下载好后就让他下载安装,由于国内速度很慢,所以我也是晚上睡觉挂机下载一晚上,第二天早上看见下载好了的
先说UI怎么用吧
UI相关
- Add:添加一个目录(可以同步到Github)
- Create:新建一个目录(也是可以同步到Github)
- Clone:从你的Github账号下载一个profile
- 最上方有Changes和History
- Changes:显示更改过的项目(你更改文件后会立即显示出来)
- History:显示同步的历史,可以倒退回某个版本
- 上面的圆点就是你的版本,点一下就是同步过的哪个版本
同步方法
- Create一个profile或者Add一个profile
- 然后在文件夹里添加一个文件
- Changes就会显示出你修改过的文件
- 底下的Sunmmary是标签(一定要写点东西,比如hexo相关的就写Hexo),Description是备注
- 填好后不出意外Commit to master就不是灰色的了
- 点击右上角的Syncing就同步了

Hexo搭建
安装
CD到你指定的目录,打开Gitbash,输入 npm install -g hexo执行安装
CD使用:比如指定到D盘,cd d:,指定到某个目录 cd d:github/hexo
或者直接到即将安装的目录右键点击Git bash here也可以
**初始化 **
指定要安装目录执行hexo init
博主是直接安装到了hexo目录下并且同步到git hub了的
生成静态页面
CD到安装目录下hexo generate
本地启动
启动本地服务hexo server
浏览器输入http://localhost:4000即可浏览
请使用高级浏览器,chrome,firefox,edge都可以,自行尝试
写文章
执行hexo new [标签] "文章名"命令之间中间有空格
文章保存在hexo\source\_posts\postName.md
**标签 **
可以不用写,所以也可以执行hexo new "文章名"
你也可以自行添加默认标签hexo\scaffolds\post.md
1 2 3 4 5 6 7 8 9 10
| title: { { title } } date: { { date } } tags:``` 想添加其他的参数可以直接插入一行 `categories:`
* **生成的文章** 地址在`hexo\source\_posts\postName.md`
|
title: postName #文章页面上的显示名称,可以任意修改,不会出现在URL中
date: 2013-12-02 15:30:16 #文章生成时间,一般不改,当然也可以任意修改
categories: #文章分类目录,可以为空,注意:后面有个空格
tags: #文章标签,可空,多标签请用格式[tag1,tag2,tag3],注意:后面有个空格
·······
这里开始使用markdown格式输入你的正文。
1 2 3 4 5 6
| * **文章摘要** ``` 以上是摘要 <!--more--> 以下是余下全文
|
主页中你肯定不想直接显示一长篇的文章吧,用这个就行
主题安装
博主用的yilia主题
主题下载到到本地,然后放到themes文件夹里
然后在根目录下打开_config.yml,将底下的(似乎是66行)theme更改为yilia
就是你下载的主题的名字,记得是theme:空格yilia
此文件任何一个冒号后面必须加空格!!!
评论框
墙裂建议使用多说评论,先注册一个账户
然后打开theme/yilia目录下的_config.yml
duoshuo: 你在多说的ID
这个主题更改方式很简单,如果使用其他主题,请自行搜索其他教程= =
至此Hexo就搭建完成
Hexo部署到GitHub
打开根目录下_config.yml,修改最底下的
1 2 3 4
| deploy: type: git repository: git@github.com:你的ID/你的ID.github.io.git branch: master
|
可以复制上面的进行修改
然后执行
hexo deploy
如果报错

将deploy 的 type 改成 git,执行
npm install hexo-deployer-git --save
重新执行hexo deploy
好了,如果成功部署,那么打开
你的ID.github.io/
应该有效果咯~
我自己还碰到个错误
hexo deploy后提示Permission denied (publickey)

试试接着ssh -T -v git@github.com 看下具体信息
http://blog.csdn.net/sunnypotter/article/details/18948053
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| enSSH_6.1p1 Debian-4, OpenSSL 1.0.1c 10 May 2012 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to github.com [192.30.252.131] port 22. debug1: Connection established. debug1: identity file /home/sunny/.ssh/id_rsa type -1 debug1: identity file /home/sunny/.ssh/id_rsa-cert type -1 debug1: identity file /home/sunny/.ssh/id_dsa type -1 debug1: identity file /home/sunny/.ssh/id_dsa-cert type -1 debug1: identity file /home/sunny/.ssh/id_ecdsa type -1 debug1: identity file /home/sunny/.ssh/id_ecdsa-cert type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1+github5 debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1+github5 pat OpenSSH_5* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.1p1 Debian-4 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr hmac-md5 none debug1: kex: client->server aes128-ctr hmac-md5 none debug1: sending SSH2_MSG_KEX_ECDH_INIT debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48 debug1: Host 'github.com' is known and matches the RSA host key. debug1: Found key in /home/sunny/.ssh/known_hosts:1 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: Roaming not allowed by server debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Trying private key: /home/sunny/.ssh/id_rsa debug1: Trying private key: /home/sunny/.ssh/id_dsa debug1: Trying private key: /home/sunny/.ssh/id_ecdsa debug1: No more authentication methods to try. Permission denied (publickey).
可以发现在一下几行出现问题: debug1: Next authentication method: publickey debug1: Trying private key: /home/sunny/.ssh/id_rsa debug1: Trying private key: /home/sunny/.ssh/id_dsa debug1: Trying private key: /home/sunny/.ssh/id_ecdsa debug1: No more authentication methods to try. Permission denied (publickey).
它一直在查找id_rsa、id_dsa、id_ecdsa这三个文件,然后就不尝试其他了 我们查看下 ~/.ssh文件夹下的文件:ls ~/.ssh github github.pub ... 这里没查找的文件,github是创建ssh-key时输入的名字 现在我们让~/.ssh文件夹下,还原当初没有改时的名字id_rsa github改名id_rsa,gitbub.pub改名id_rsa.pub 再次尝试连接:ssh -T git@github.com Hi xxx ! You've successfully authenticated, but GitHub does not provide shell access.成功。
|
命令简写
- hexo g == hexo generate
- hexo d == hexo deploy
- hexo s == hexo server
- hexo n == hexo new
- 还能组合使用,如:
- hexo d -g
申请域名
参考我的另外一篇教程购买域名
放几个其他的教程上来,需要的看他们的就行啦~
http://www.tuicool.com/articles/AfQnQjy/
http://sunwhut.com/2015/10/30/buildBlog/
完结撒花
★,°:.☆( ̄▽ ̄)/$:.°★