Hexo Tips

通过Hexo 安装教程,我们已经能基本使用Hexo了。但是笔者在使用过程中还是遇到了一些问题,在这一篇中希望能总结一些经验,不能说是很有用的东西,也只是希望做一个记录。遇到了能在这里找到解决方法。

代码提交到了Github上

我把hexo的源码和主题的修改都用Git提交到了Github上,如果想看本站源码可以down下来,Git具体操作这篇文章介绍的很详细,我也是通过这篇文章Get到套路的。

Node forever

在搭好环境后,我发现有时候莫名其妙的Hexo就挂了,然后整个网站就无法浏览,实际上通过Node forever 就可以解决这个问题,原理就是在后台用定时任务去跑

1
$ hexo server

如果挂了就重启。具体怎么做呢?

  • 通过npm安装forever
  • 在hexo目录下写好一个javascript脚本
  • 通过forever定时执行该脚本

1、通过npm安装forever,执行如下命令安装forever

1
$ sudo npm install forever -g #安装

2、在hexo的根目录下新建一个haymai.js文件,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var spawn = require('child_process').spawn;
free = spawn('hexo', ['server', '-p 80']);
free.stdout.on('data', function (data) {
console.log('standard output:\n' + data);
});
free.stderr.on('data', function (data) {
console.log('standard error output:\n' + data);
});
free.on('exit', function (code, signal) {
console.log('child process eixt ,exit:' + code);
});

3、执行如下命令跑定时任务:

1
$ forever --minUptime 10000 --spinSleepTime 26000 start haymai.js

加入RSS和Sitemap

1、在Hexo根目录执行

1
2
$ npm install hexo-generator-feed
$ npm install hexo-generator-sitemap

2、在Hexo根目录下加入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Extensions
Plugins:
- hexo-generator-feed
- hexo-generator-sitemap
#Feed Atom
feed:
type: atom
path: atom.xml
limit: 20
#sitemap
sitemap:
path: sitemap.xml

3、执行hexo clean和hexo deploy 后,打开haymai.cc/atom.xml,haymai.cc/sitemap.xml即可看到已生效

公益404页面

haymai.cc/aaa -> 腾讯公益
这个真心蛋疼死了,网上大多数人说只要把一个404.html放进source文件夹就行了,但是我放了死活不行,结果找了半天,原来是用

1
$ hexo server

启动的不会去跳转到404.html,这不就是说hexo 没有这功能?! 最终我只好祭出杀手锏,抛弃 hexo启动,转而将public文件夹路径指向了tomcat ROOT应用,然后配置ROOT下的web.xml如下内容:

1
2
3
4
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>

当然source下的404.html 也要加上,这里用了腾旭公益404页面,内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
layout: false
title: "404"
---
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8;"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="robots" content="all" />
<meta name="robots" content="index,follow"/>
</head>
<body>
<script type="text/javascript" src="http://www.qq.com/404/search_children.js" charset="utf-8" homePageUrl="http://www.haymai.cc" homePageName="回到唐伯虎点蜡烛"></script>
</body>
</html>

不知道各位看官是怎么解决的,有没有更好的方法?

网易云音乐引入

哈哈,网站第一次发声,链的网易云,在页面上加入如下代码,你也能听我的红心啦~23333

1
2
3
<div style="max-width: 350px;max-height: 150px">
<embed style="margin-top: -35px;" frameborder="no" border="0"marginwidth="0" marginheight="0" src="https://music.163.com/outchain/player?type=0&id=28560713&auto=0&height=90"></embed>
</div>


作者 夏目
2016 年 04月 09日

叔叔,阿姨给点钱买棒棒糖吃