Hello Hexo

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
hexo new "My New Post"

More info: Writing

Run server

1
hexo server

More info: Server

Generate static files

1
hexo generate

More info: Generating

Deploy to remote sites

1
hexo deploy

草稿

草稿相当于很多博客都有的“私密文章”功能。

1
hexo new draft "new draft"

会在source/_drafts目录下生成一个new-draft.md文件。但是这个文件不被显示在页面上,链接也访问不到。也就是说如果你想把某一篇文章移除显示,又不舍得删除,可以把它移动到_drafts目录之中。

如果你希望强行预览草稿,更改配置文件:

1
render_drafts: true

或者,如下方式启动server:

1
hexo server --drafts

下面这条命令可以把草稿变成文章,或者页面:

1
hexo publish [layout] <filename>

More info: Deployment

MathJax

在blog文件夹中执行:

1
hexo math install

_config.yml文件中添加:

1
2
plugins:
- hexo-math

使用

1
Simple inline $a = b + c$.

效果:

Simple inline $a = b + c$.

MathJax Block:

1
2
3
4
$$\frac{\partial u}{\partial t}
= h^2 \left( \frac{\partial^2 u}{\partial x^2} +
\frac{\partial^2 u}{\partial y^2} +
\frac{\partial^2 u}{\partial z^2}\right)$$

效果:

$$\frac{\partial u}{\partial t}
= h^2 \left( \frac{\partial^2 u}{\partial x^2} +
\frac{\partial^2 u}{\partial y^2} +
\frac{\partial^2 u}{\partial z^2}\right)$$

为Hexo Next博客添加关键词功能

修改文件:themes\next\layout_partials\head.swig

1
2
3
4
5
6
7
{% if page.keywords %}
<meta name="keywords" content="{{ page.keywords }}" />
{% elif page.tags and page.tags.length %}
<meta name="keywords" content="{% for tag in page.tags %}{{ tag.name }},{% endfor %}" />
{% elif theme.keywords %}
<meta name="keywords" content="{{ theme.keywords }}" />
{% endif %}

修改内容:35行左右,将原来的设置ketwords的代码覆盖即可

1
2
3
4
5
6
7
{% if page.keywords and page.keywords.length %}
<meta name="keywords" content="{% for key in page.keywords %}{{ key }},{% endfor %}" />
{% elif page.tags and page.tags.length %}
<meta name="keywords" content="{% for tag in page.tags %}{{ tag.name }},{% endfor %}" />
{% elif theme.keywords %}
<meta name="keywords" content="{{ theme.keywords }}" />
{% endif %}

hexo 中设置访问密码

themes->next->layout->_partials->head.swig中的meta标签之后添加js代码

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
<script src="https://cdn.bootcss.com/js-sha1/0.4.1/sha1.js"></script>
<script src="http://cdn.bootcss.com/blueimp-md5/1.1.0/js/md5.js"></script>

<script type="text/javascript">
loopy()
function loopy() {
if('{{ page.password }}'){
while(true) {
var pass = prompt("输入正确密码才能查看!");
if(pass) {
// 点击的确定
var ss = sha1(pass)
// alert(ss);
if(ss == '{{ page.password }}') {
alert("欢迎进入我的博客!Contact me at zhangshenghao1995@163.com");
break;
}
else {
alert("密码错误!");
}
}
else if(pass == "") {
// 用户没有输入
}
else {
// 点击取消
history.back()

}
}
}
}
</script>

安装扩展包

1
sudo npm install hexo-math --save

Pandoc 的问题

Error: spawn pandoc ENOENT

1
2
3
4
5
6
7
8
9
10
events.js:183
throw er; // Unhandled 'error' event
^

Error: spawn pandoc ENOENT
at _errnoException (util.js:1022:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
at onErrorNT (internal/child_process.js:372:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

解决方案: 安装 pandoc

Error: -smart/-S removed

1
2
3
4
5
6
7
8
9
Error: pandoc exited with code 2: --smart/-S has been removed.  Use +smart or -smart extension instead.
For example: pandoc -f markdown+smart -t markdown-smart.
Try pandoc --help for more information.

at ChildProcess.<anonymous> (/home/arxan/go_project/src/blog_hexo/node_modules/hexo-renderer-pandoc/index.js:73:20)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
打赏