Mac安装Hexo

安装nvm

因为brew安装nvm会有问题,所以推荐用传统方法安装[1]

brew install curl
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash

删除

to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)

升级

cd "$NVM_DIR" && git pull origin master && git checkout `git describe --abbrev=0 --tags`

安装node.js

nvm install 4
nvm use 4.2.6

预设使用Node的版本,否则每次重新登入,都要nvm use一次[2]

nvm alias default 4.2.6

测试:

nvm -v

安装Hexo

proxychains4 npm install -g hexo-cli

-g–global表示全局安装模块,如果没有这个参数,会安装在当前目录的node_modules子目录下[3]

因为GFW的问题,会在安装的时候发生错误,此时可以改用[4]

npm install hexo --no-optional

测试:

hexo -v

有可能会出现以下错误:

{ [Error: Cannot find module './build/Release/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/Debug/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }

这是由于dtrace-provider出现错误,可以通过重新安装解决:

cd .nvm/versions/node/v4.2.6/lib/node_modules/hexo-cli/node_modules/hexo-log/node_modules/bunyan

npm uninstall dtrace-provider
npm install dtrace-provider --save

初始化Hexo

hexo init <folder>
cd <folder>
npm install

启动服务(在博客所在的文件夹内)[5]:

hexo s

如果继续发生如下错误:

{ [Error: Cannot find module './build/Release/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/Debug/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }

可以继续通过重新安装dtrace-provider解决:

cd node_modules/hexo/node_modules/hexo-log/node_modules/bunyan

npm uninstall dtrace-provider
npm install dtrace-provider --save

更换主题

安装next主题

git clone https://github.com/iissnan/hexo-theme-next themes/next

然后修改\_config.yml文件,修改为:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: next

language: zh-Hans

使用Mathjax

安装插件[6]

npm install hexo-math --save

在网站的\_config.yml文件中添加:

math:
engine: 'mathjax' # or 'katex'
mathjax:
src: http://cdn.bootcss.com/mathjax/2.6.1/MathJax.js?config=TeX-MML-AM_HTMLorMML
config:
{
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
processEscapes: true
},
TeX: {
equationNumbers: {
autoNumber: "AMS"
}
},
messageStyle: "none"
}
katex:
css: # not used
js: # not used
config:
# KaTeX config

修改heading里#后的空格

为了##后不用加空格,直接写标题,可以对markdowm渲染器进行修改。把/Blogs/node_modules/hexo-renderer-marked/node_modules/marked/lib/marked.js改为:

heading: /^ *(#{1,6})+([^\n]+?) *#* *(?:\n+|$)/

支持footnote

可以通过将markdown渲染器替换为hexo-renderer-markdown-it,使得支持footnote功能[7]

npm un hexo-renderer-marked --save
npm i hexo-renderer-markdown-it --save

必须要先卸载原先的渲染器。然后在网站\_config.yml文件中添加:

markdown:
plugins:
- markdown-it-footnote

然后发现每一条footnote间都有一行间隔。想要去掉的话,可以在'/Blogs/themes/next/source/css/_custom/custom.styl'中添加:

.footnote-item p {
margin-bottom: 0
}

hexo-renderer-markdown-it还支持很多其他的功能,具体可以到官网了解。

Doesn't escape HTML content

hexo-renderer-markdown-it is the default renderer of my Hexo blog. But I found that the HTML content inside the md will be escaped to the final result when I wanted to force a line-break by inserting a <br> tag.

To trigger this function, the configuration of the \_config.yml in the blog should be:

markdown:
render:
html: true

where[8]:

html: true # Doesn't escape HTML content
## OR
html: false # Escapes HTML content so the tags will appear as text.

支持插入pdf

npm install --save hexo-pdf

使用[9]

# Normal PDF
{% pdf http://7xov2f.com1.z0.glb.clouddn.com/bash_freshman.pdf %}

#Google drive
{% pdf https://drive.google.com/file/d/0B6qSwdwPxPRdTEliX0dhQ2JfUEU/preview %}

#Slideshare
{% pdf http://www.slideshare.net/slideshow/embed_code/key/8Jl0hUt2OKUOOE %}

  1. https://github.com/creationix/nvm

  2. http://mac-osx-for-newbie-book.kejyun.com/software/softwareWebDeveloperNodeJS.html

  3. https://www.haomwei.com/technology/how-to-install-hexo-on-mac.html

  4. http://www.jianshu.com/p/fd878edb95e7

  5. https://hexo.io/docs/

  6. https://github.com/akfish/hexo-math

  7. https://github.com/celsomiranda/hexo-renderer-markdown-it

  8. https://github.com/celsomiranda/hexo-renderer-markdown-it/wiki/Advanced-Configuration

  9. https://github.com/superalsrk/hexo-pdf