终于搭建好了自己的博客,借助前辈们的基础,自己也踩了几个坑。
下面就谈谈,身为菜鸟的我,是怎么一步步操作的。

一、Hexo搭建

1. 必要软件下载

node.js:https://nodejs.org/en/
git:https://git-scm.com/downloads/

2. Github账号注册和Repository创建

申请页面:https://github.com/
记录好 用户名,Email,密码
新建Repository,我的库名为AprilSpring.github.io

3. 创建SSH秘钥

打开git bash终端,输入

git config --global user.name "你的GitHub用户名"
git config --global user.email "你的GitHub注册邮箱"

这里需要你上面的用户名和邮箱。

4. 生成SSH秘钥

ssh-keygen -t rsa -C "你的GitHub注册邮箱"
不用管弹出来的东西,直接回车就OK。
此时,在C:/Users/User/下,生成一个.ssh文件夹,记事本打开其中的id_rsa.pub,并拷贝。
然后,打开Github,AprilSpring.github.io -> Settings -> Depoly keys -> New SSH key -> 将id_rsa.pub中的内容复制到Key文本框中,记住勾选Allow write access,然后点击Add SSH key(添加SSH)按钮。

5. 开始安装Hexo

打开你的终端(可以用cmd),进入到blog下面:

npm install hexo-cli g  #安装hexo
hexo init blog  #初始化博客文件夹
cd blog  #切换到该路径
npm install  #安装hexo的扩展插件
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

6. 更改配置文件

打开blog/_config.yml,进行下面修改:

deploy:
  type: git
  repo: git@github.com:AprilSpring/AprilSpring.github.io.git
  branch: master

值得注意的是,git@github.com:???/&&&.git,???应该为你Github的用户名,而&&&应该为你Github库的名字。
此外,其中的url和root更改为:

url: https://aprilspring.github.io/
root: /

为了避免弄错,可以先备份一份。

7. 部署到Github服务器上

首先,生成静态页面:hexo generate 或 hexo g
而后,可以通过开启开启本地服务器来查看我们的Blog:hexo sever 或 hexo s
将Blog部署到Github服务器上:hexo deploy 或 hexo d
有时,你可能还需要先清除静态页面:hexo clean,来从新部署。
这时,打开你的网页:https://aprilspring.github.io/
~~~你的博客来了!

二、Hexo主题更换

看了网上的几个Theme后,我选择了Next主题。
http://theme-next.iissnan.com/getting-started.html 这个网页写的很详尽,就按照他的步骤安装和更改配置文件。
我选择了scheme: Pisces,还可以添加头像,棒棒的!

三、添加菜单

  1. 如果已经安装好了Next,就没有必要再额外添加菜单啦,因为在Next里面,就有参数可以选择菜单的添加。
  2. 否则,请按下面进行:
    新建一个页面,也就是添加新菜单,我们的这个菜单叫做"About":hexo new page "about"
    然后你会发现source里面多了个目录about,里面有个index.md。
    接着修改blog/themes/theme_name/_config.yml文件,找到里面的menu项,添加一行About: /about
  3. 那么如何编辑about呢?
    直接修改source/about/index.md文件就ok啦。完美。
  4. 同样的方式,可以添加并编辑Categories和Tags。
    我的Catagories和Tags分别如下:
---
title: Categories
date: 2017-04-12 15:05:25
type: "categories"
comments: false
---

---
title: Tags
date: 2017-04-12 15:05:25
type: "tags"
comments: false
---
categories:

# 四、写一个博客 ## 1. 新建一个博客 `hexo new post "BlogName"` 然后,去blog/source/_posts/下面,找到这个BlogName.md,Notepad打开,进行编辑。

2. 常用的MakeDown修饰语言

比如:字体、字号、加粗、缩进等。
参见:http://blog.csdn.net/u011419965/article/details/50536937 #字体字号颜色
特殊符号前面用反斜线""。

3. 插入图片

首先,更改blog/_config.yml文件中的 post_asset_folder: true
然后,运行: npm install https://github.com/CodeFalling/hexo-asset-image --save
确保在blog/source/_posts下创建和md文件同名的目录,在里面放该md需要的图片。
目录结构如下:
———————————————————
|- source/_posts
  |- test.md
  |- test
    |- pic.png
———————————————————
而后,在test.md文件中需要插入图片的地方写上:
![](目录名/文件名.png),也即 ![](test/pic.png)
最后,依次执行:hexo clean、hexo g、hexo d,怎么样?图片在了吧?!

4. 添加Read more

如果博文过长,可以在文中添加<\!--more--\>,则该标记之前的部分就会成为该文章的简述,显示在首页里,其余隐藏。

5. 随时编辑

在编辑博客的时候,可以hexo s打开本地服务器的博客,随时保存并刷新页面,以便查看自己写的博客,等完成之后一并部署。


# 五、还要解决的问题 1. 在线的Markdown编辑器,方便边编辑、边部署 2. 换了一台电脑,我该怎么写博客?怎么移植过去,还是? 3. 另外,About还是打不开的原因? 解决方案: 修改.deploy_git文件夹 ->.git文件夹下的config 文件,将ignorecase=true 改为 ignorecase=false,重新部署,问题解决。 参考:http://1mhz.me/2015/hexo-deploy-case-sensitive/
# 特别鸣谢 http://blog.csdn.net/xuezhisdc/article/details/53130328 https://github.com/iissnan/hexo-theme-next http://theme-next.iissnan.com/getting-started.html https://segmentfault.com/q/1010000000618915 http://blog.csdn.net/u011419965/article/details/50536937#字体字号颜色 http://www.cnblogs.com/palance/p/5493201.html https://www.zhihu.com/question/52523619 https://segmentfault.com/q/1010000002561642