安装nvm
因为brew安装nvm会有问题,所以推荐用传统方法安装。
1 2 brew install curl curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
删除
1 to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)
升级
1 cd "$NVM_DIR" && git pull origin master && git checkout `git describe --abbrev=0 --tags`
安装node.js
1 2 nvm install 4 nvm use 4.2.6
预设使用Node的版本,否则每次重新登入,都要nvm use
一次。
测试:
安装Hexo
1 proxychains4 npm install -g hexo-cli
-g
或–global
表示全局安装模块,如果没有这个参数,会安装在当前目录的node_modules子目录下。
因为GFW的问题,会在安装的时候发生错误,此时可以改用:
1 npm install hexo --no-optional
测试:
有可能会出现以下错误:
1 2 3 { [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出现错误,可以通过重新安装解决:
1 2 3 4 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
1 2 3 hexo init <folder> cd <folder> npm install
启动服务(在博客所在的文件夹内):
如果继续发生如下错误:
1 2 3 { [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解决:
1 2 3 4 cd node_modules/hexo/node_modules/hexo-log/node_modules/bunyan npm uninstall dtrace-provider npm install dtrace-provider --save
更换主题
安装next主题
1 git clone https://github.com/iissnan/hexo-theme-next themes/next
然后修改\_config.yml
文件,修改为:
1 2 3 4 5 6 # Extensions ## Plugins: https://hexo.io/plugins/ ## Themes: https://hexo.io/themes/ theme: next language: zh-Hans
使用Mathjax
安装插件:
1 npm install hexo-math --save
在网站的\_config.yml
文件中添加:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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
改为:
1 heading: /^ *(#{1,6})+([^\n]+?) *#* *(?:\n+|$)/
可以通过将markdown渲染器替换为hexo-renderer-markdown-it
,使得支持footnote功能。
1 2 npm un hexo-renderer-marked --save npm i hexo-renderer-markdown-it --save
必须要先卸载原先的渲染器。然后在网站\_config.yml
文件中添加:
1 2 3 markdown: plugins: - markdown-it-footnote
然后发现每一条footnote间都有一行间隔。想要去掉的话,可以在'/Blogs/themes/next/source/css/_custom/custom.styl'中添加:
1 2 3 .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:
1 2 3 markdown: render: html: true
where:
1 2 3 html: true # Doesn't escape HTML content ## OR html: false # Escapes HTML content so the tags will appear as text.
支持插入pdf
1 npm install --save hexo-pdf
使用:
1 2 3 4 5 6 7 8 # Normal PDF {% pdf http://7xov2f.com1.z0.glb.clouddn.com/bash_freshman.pdf %} #Google drive {% pdf http://drive.google.com/file/d/0B6qSwdwPxPRdTEliX0dhQ2JfUEU/preview %} #Slideshare {% pdf http://www.slideshare.net/slideshow/embed_code/key/8Jl0hUt2OKUOOE %}