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.

hexo常用命令

初始化hexo

1
2
$ hexo init dirname
$ npm install

创建新发布

1
$ hexo new "My New Post"

More info: Writing Writing-Chinese

启动server

1
$ hexo server

或者

1
$ hexo s

More info: Server

生成静态文件

1
$ hexo generate

或者

1
$ hexo g

More info: Generating

部署到远程地址

1
$ hexo deploy

或者

1
$ hexo d

更换新的主题

  • 克隆新的主题到theme目录
1
$ git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia
  • 打开_config.yaml把theme字段的值修改为刚才在theme目录里的主题名
1
theme: yilia
  • clear完以后重新部署
1
2
3
$ hexo g
$ hexo s
$ hexo d

使用MathJax 写公式示例

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)\]

More info: MathJax


hexo部署问题

语言切换

在_config.yaml中修改language字段

1
language: zh-Hans

执行hexo g报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
ERROR Script load failed: themes/next/scripts/tags/exturl.js
Error: Cannot find module 'hexo-util'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (/root/hexo/node_modules/hexo/lib/hexo/index.js:213:21)
at /root/hexo/themes/next/scripts/tags/exturl.js:8:12
at /root/hexo/node_modules/hexo/lib/hexo/index.js:229:12
at tryCatcher (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:638:18)
at Promise._resolveCallback (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:432:57)
at Promise._settlePromiseFromHandler (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:524:17)
at Promise._settlePromise (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:693:18)
at Promise._fulfill (/root/hexo/node_modules/hexo/node_modules/bluebird/js/release/promise.js:638:18)
at /root/hexo/node_modules/hexo/node_modules/bluebird/js/release/nodeback.js:42:21
at /root/hexo/node_modules/hexo/node_modules/hexo-fs/node_modules/graceful-fs/graceful-fs.js:78:16
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)

解决办法:

1
npm install -save-dev hexo-util

启动失败

报错信息:

1
访问浏览器出现 cannot GET /

解决信息:

1
2
3
下面两步要一起执行
hexo init
npm install

hexo支持mathjax

hexo支持category与tag

打开scaffolds/post.md, 修改内容为

1
2
3
4
5
6
---
title: {{ title }}
date: {{ date }}
tags:
categories:
---

以后执行hexo n 'name'生成的md文件中就会有category了

hexo支持版权声明

安装

1
npm install hexo-filter-indicate-the-source --save

配置

1
2
3
4
5
6
7
8
indicate_the_source:
pattern: indicate-the-source
enable: true
render_engine: ejs
element_class: source
domain_white_list:
- localhost
template: "<blockquote><p>转载请注明出处:<%- post.permalink %></p><p>访问原文「<a href='<%- post.permalink %>'><%- post.title %></a></p></blockquote>"

使用的时候在md文中合适的位置插入

1
<!-- indicate-the-source -->

git常用命令

设置代理

1
2
3
4
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy

修改远程分支命令

1
git remote set-url origin [url]

删除分支与添加remote分支

1
2
git remote rm origin
git remote add origin [url]

用远程的覆盖本地

1
2
git fetch --all  
git reset --hard origin/master

设置upstream

1
2
3
git branch --set-upstream-to=origin/dev
或者
git branch -u origin/dev

取消当前分支的upstream

1
git branch --unset-upstream

取消指定分支的upstream

1
git branch --unset-upstream [分支名]

查看upstream,打开.git/config文件

报错Git: fatal: Pathspec is in submodule

1
2
git rm --cached directory
git add directory

参考资料