抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

靖待的技术博客

小清新IT旅程 | 为中华之崛起而读书


配图

hexo+github博客搭建中出现的问题及解决方法。
博客优化和高级进阶请看–>hexo优化·年轻就是折腾


2016.8.28更新 Update

插件 plug-in unit

1
2
3
4
5
6
7
8
9
npm install hexo-generator-index --save
npm install hexo-generator-archive --save
npm install hexo-generator-category --save
npm install hexo-generator-tag --save
npm install hexo-server --save
npm install hexo-deployer-git --save
npm install hexo-generator-sitemap --save
npm install hexo-generator-feed --save
npm install hexo-git-backup --save

hexo插件

2016.4.7更新 Update

  每次hexo d之后都要输入密码,很影响心情,于是决定重新设定SSH,这次不再设定密码。现把流程记录下来备忘。
It affects mood to input password everytime I execute hexo d.So I decide to reset SSH and no password.Now write the steps down.

几条重要指令 Several important instructions

  查看是否存在SSH文件。
To cheak if SSH file exists.

1
ls -al ~/.ssh

  存在的话,直接删除.ssh文件夹里面所有文件,同时在github上删除SSH。
Delete all the files if it exist and delete SSH on the github.

1
ssh-keygen -t rsa -C "4177997456@qq.com"

  回车三次(因为密码为空)。
Press enter three times(for keyword is empty).

1
ssh-agent -s
1
ssh-add ~/.ssh/id_rsa

  出错。Something wrong.
  换成 Change into

1
2
eval `ssh-agent -s`
ssh-add

  完成。Finish.
  可以直接打开.ssh文件夹里的id_rsa.pub复制全部内容,也可以输入
You can copy id_rsa.pub in the .ssh file,or input
1
clip < ~/.ssh/id_rsa.pub

然后在github里设置好SSH即可。
then set SSH on the github.
  最后测试一下:
Test it finally,
1
ssh -T git@github.com

  如果出现 成功画面 证明设置好了。
If it showssucess that all is done.

  然而……
However~
  依!然!报!错!
Still wrong!
报错画面wrong

  这是为什么……在hexo d好几次后的我凌乱在风中……
  但我没有放弃……毕竟不能把博客玩废啊是不是:-D
  我想起来昨天把博客同步托管在github和coding上了。
  因为我的repo先写的coding,再写的github,所以服务器先连接coding,后连接github!!!
  两个托管网站都要设置好SSH之后,才能顺利部署!
  完工!
  再也不用打密码啦~

WHY?!After several times hexo d,I was messy in the wind~
But I’m never give up~I can’t destory my blog after all :D
I remind of having got my blog hosted on GitHub and coding yesterday.
My repo place coding to the front,so the sever links coding first,then the github!!!
Only two host webs be setted SSH,can it be well deployed!
Finish!
Never using password~
Say goodbye to you~


2015.11.06更新 Update

今天建好了大体的框架,细节还需不断调整。现把我搭建过程中出现的若干问题以及解决方案写下来,方便自己及读者不再为这些地方犯难。
Today the frame generally build,and details needs improving. Now I note my problems and solutions for the readers no longer to puzzle again.

安装 Install

  安装顺序不要错,出现WARN不用管。
  我们都知道需要安装git和node.js,然后才能安装hexo。
  简单介绍:Hexo 是一个快速、简洁且高效的基于Node的静态博客框架。
  按理来说,从官网把软件下载下来安装,一路next就行。
  打开git bash命令行,输入:

Installation sequence is important,and you can ignore the warning in the process.
We know that git and node.js are needed,and then hexo can be installed.
In brief,hexo is a fast, simple and efficient static blog framework which bases on Node.
Having downloaded the software and installed,and then you just click “next”.
Input this in the git bash:

1
$ npm install -g hexo-cli

这时会发现,和很多教程所授不同啊!出现了多个WARN。不要慌!WARN可以不用管。我当时查了很久,怎么才能不WARN,后来发现其实不影响之后的搭建。

At this moment you will puzzle that it is different with many tutorials.It turns out some warning!Calm down,guys,you can ignore them.It doesn’t matter.

开始建站 Set

  建站前直接在目标盘建立一个hexo文档,对hexo右键git bash。
  记住一定在目标目录里建站!
  一开始我不清楚,点击桌面上的git bash就输命令,后来都不好找hexo文件在哪,严重影响之后的体验!
  之后同样的,npm加到目标目录中!

At first,you should create a hexo file,and git bash with right click.
Remember to set your blog in the target file!
I made the mistake that git bash on the desktop,which resulted in the loss of hexo file.It’s bad for later set.
And then,the same,add npm to the target file!

1
$ npm install

就这三步,本地的网站其实就建立好了!看起来好简单!运气不好的话就会像我一样,卡在最开始耽误了很多时间。

Having done these three steps,our local web is already set!Is it really easy?But you may waste much time as I did.

本地预览 Local preview

  因为在Hexo 3.0后server被单独出来了,需要安装server,记住打下面一行代码:
Because server was divided after hexo 3.0,you should install server,and remember these code,

1
$ npm install hexo-server --save

之后是:
and then,
1
$ hexo server

本地端口已经打开,通过浏览器访问http://localhost:4000/ 可以看到网站。

The local port has set,and you can cheak on http://localhost:4000/ through browser.

注意细节 Pay attention to details

  下载一个编辑器,我下载的是Sublime Text 2,一定要有编辑器,否则很多属性不能修改。
  找到hexo文件夹,打开_config.yml,这里面就是网站的配置信息。具体配置hexo讲的很明白,我就不解释了。
  我刚开始就是胡乱搭建,找不到hexo文件,更不用谈之后的配置。这里要擅用电脑里的文件搜索,有它还是可以方便的找出文件。
  Hexo采用markdown语法格式书写博客,其中我们的博文就放在source里的_posts目录。

To download a editor.What I use now is Sublime 2.You need a editor for modify attributes.
The _config.yml in the hexo file is the web configuration information.The specific configuration I won’t say it here.
I structures it at random at first,because I couldn’t find hexo file.A good tip is to use file search to find what you want conveniently.
Hexo uses markdown grammer to write,and our articles are saved in the _posts file.

写新文章 Create a new article

1
$ hexo new title

  其中title为你的博文文件的文件名,不一定是博文的标题,只要自己看得懂就行。然后点开source里的_posts目录,打开title.md,我们就可以在里面进行写作了。当然,有一些语法规定及格式要求,我也还在学习中。

The title is your article file name,not your article name,so just you understand is alright.

  之后需要静态化页面:

1
$ hexo generate

hexo部署:

1
$ hexo deploy

  此时本地站点大体搭建好了。
Now the local site is set.

  如果配置_config.yml出错,本地网站是一定搭不好的!
  而_config.yml中比较难发现的就是,每一个红体单词冒号后要空格!!!

If the _config.yml is wrong,your site can’t be create.
The detail easy to overlook is that there leaves a blank space after colon!!!

  接下来把网站部署到github上。
  首先去github上注册个账号。
  再建立一个新的repositories。名称是username.github.io,这也是最终搭建好的博客的链接地址。

The following thing is to deploy the site on the github.
At the beginning,you should have a github account.
Then you should create a new repositories,which name is username.github.io,and it is your blog link address.

勿用github自动页面生成器 Do not use the github automatic page generator

  尤其初学者!否则之后的hexo博客很难部署上去!
  如果已经用了自动页面生成器,可以删除这一个repositories,再新建一个。
  在完成上述操作后,到Hexo文件夹下的_config.yml文件,将最下方的deploy部分修改为

Exspecially a beginer!
If you use it already,you can delete this repositories,and create another.
After all the steps done,revise the deploy of the _config.yml as

1
2
3
$ deploy
type: git
repo: git@github.com:username/username.github.io.git

  每个冒号后有一个空格!!!
  到此,github配置完成。

There leaves a blank space after each colon!!!*
So much for that,the deploy is done.

  现在要把hexo和github联系在一起,还需要SSH。
  首先,打开git bash:

If hexo links to github,SSH is needed.
Open git bash,

1
2
$ git config --global user.name "XXX"
$ git config --global user.email "XXXXXX@mail.com"

  邮箱是你注册github的邮箱。
  生成密钥:

The e-mail is your github e-mail.
Create private key,

1
$ ssh-keygen -t rsa -C “XXXXXX@mail.com”

  然后设置路径,最好不要更改id_rsa和id_rsa.pub的名字。

  密码可有可无(最好无),但输入时你也看不到自己输的密码的。
登录github,在右上角settings(不是repositories里的settings)有SSH keys。
复制你设置路径里的id_rsa.pub用编辑器打开得到的代码,粘贴到SSH keys,标题自定义。
验证:

Set path,and don’t change id_rsa and id_rsa.pub name.
The password is not esstial(none maybe convinent),but you can’t see it when you enter the code.
Then you sign in the github,and finds SSH keys in the setting(not setting in the repositories).
Copy your code in the id_rsa.pub,and paste it to SSH keys.Customizable title is needed.
Verity,

1
$ ssh -T git@github.com

一般来说,是会报错的。Permission denied (publickey).让多少人揪心的一句话。

Generally,something goes wrong.”Permission denied (publickey)”,may let you not happy.

复制公钥 Copy public key

  用计算机搜索文件.ssh文件,找出目标路径,之前设置的id_rsa和id_rsa.pub复制到这里来!
同时,如果多次设置SSH,最好把其中一个known开头的文件里前几次的公钥清空。
成功的标志:

Search .ssh file in the computer,and paste id_rsa and id_rsa.pub to it.
If you set SSH many times,you’d better clear the previous public key in the known-start file.
The success sign,

1
$ Hi username! You've successfully authenticated, but GitHub does not provide shell access.

最后,

In the end,

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

基本指令 Basic instructions

  每次修改或者发文后,这两条命令一定要打,否则博客不能更新:

Everytime you revise or create a article,two instrucions are needed,or your post can’t be updated.

1
2
$ hexo generate
$ hexo deploy

$ hexo server 为在本地端口打开。
(简记abbreviation hexo g hexo s hexo d)
  期间还遇到一些小问题,不典型,就不说啦。总之,初学者刚开始搭建一定要有耐心,我仅是node.js就重装了五遍以上,有时候看教程很复杂,其实一步步做不难!不要放弃!跟着一个教程做出现问题时,及时在网上寻求答案,查看其它的教程。我在搭建此博客时,查阅的教程几十种了,很多人的方法很好,也算是走捷径了!

There exists many small problems in the process.In short,the patience is vital during the course.According to me,I reset node.js for more than five times.The tutorial maybe complex,but you can feel easy if you do it step by step!Never give up!When any problem arise,it is useful to search solutions on the internet or looking up in another tutorial.I call the tips a shortcut.

  以上,就是我搭建过程中出现的问题及解决方案。

  Above,it is the problems and solutions in the process.


参考资料 Reference material

1.hexo与github_pages搭建博客教程
2.hexo你的博客
3.hexo干货系列(一)
4.hexo常见问题解决方案


评论