Hello World

不能免俗必然是Hello World!那就简单分享一下是如何利用Hexo和Github建站的吧。总共分三步:

  1. 安装node.js及git
  2. 安装hexo
  3. Github创建pages页面并部署
  4. 图床及其他插件配置

安装node.js

直接去官网下载相应的安装包就好了。这里我下载的Mac OS X Installer (.pkg)。

Mac OS X自带Git……

安装hexo并配置

安装Hexo并初始化

在终端输入如下命令安装Hexo:

$ npm install -g hexo-cli

Mac OS X虽然不用安装git但需要安装XCode否则可能安装过程中编译会报错。

装好Hexo后新建一个文件夹就可以初始化Hexo啦,

1
2
3
$ hexo init <folder>
$ cd <folder>
$ npm install

Hexo自带的Hello World文档教你Quick Start

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.

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

Change themes

我觉得需要有一个导文档导航的主题,所以我找到了一款yelee的主题。在Hexo所在根目录输入以下命令克隆主题:

git clone https://github.com/MOxFIVE/hexo-theme-yelee.git themes/yelee

修改 Hexo 根目录对应配置文件。

theme: yelee

Github创建pages页面并部署

Github

新建一个公共库,名为youraccount.github.io,将分支改为gh-pages。

Deploy to remote sites

安装hexo git部署工具

配置_config.yml

1
2
3
4
5
6
7
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: https://github.com/Jaybeka/jaybeka.github.io.git
brach: gh-pages
message:

本地经调试后部署。

1
$ hexo deploy

More info: Deployment

图床

七牛图床

申请了一个七牛的帐户,因为有免费的10G的空间……

并且Hexo有七牛的图片上传插件

但是我手贱将缓存地址设成了华北,上传地址变了,于是在同步的过程中会提示:

1
2
{ code: 400,
error: 'incorrect zone, please use up-z1.qiniu.com' }

但我看了一下无论是官方文档还是上传插件中都没有提及如何修改该项配置,我只能将Hexo根目录下node_modules/hexo-qiniu-sync/qiniu下的conf.js中的改了一下上传地址,问题就解决了。

1
2
//exports.UP_HOST = 'http://upload.qiniu.com';
exports.UP_HOST = 'http://up-z1.qiniu.com';

已给该插件的作者提了一个issue。该issue已被关闭,更新到最新的版本并在_config.yml中添加一行配置就可以了,如下:

1
2
qiniu:
up_host: http://up-z1.qiniu.com

原来七牛同步工具是支持修改上传地址的配置的,插件作者就在sync.js中修改了如下:

1
2
3
if(config.up_host){
qiniu.conf.UP_HOST = config.up_host;
}

Mathjax

这么高科技的网站怎么可能少了mathjax,那样人生会不完整的。

同样,贴心的前辈们已经给我们准备好了相应的插件。安装hexo mathjax。但该mathjax可能会遇到字符冲突问题,当在公式中出现两个_时程序会优先处理成斜体字,而不是公式中的下标。可参考此篇文章采用转义\跳过。

不完全参考文章:

文章目录
  1. 1. 安装node.js
  2. 2. 安装hexo并配置
    1. 2.1. 安装Hexo并初始化
    2. 2.2. Hexo自带的Hello World文档教你Quick Start
      1. 2.2.1. Create a new post
      2. 2.2.2. Run server
      3. 2.2.3. Generate static files
    3. 2.3. Change themes
  3. 3. Github创建pages页面并部署
    1. 3.1. Github
    2. 3.2. Deploy to remote sites
  4. 4. 图床
    1. 4.1. 七牛图床
    2. 4.2. Mathjax
,