Hexo Blog On Openshift

This is a static blog built by Hexo, which is a simple but powerful blog framework implemented by Node.js. Actually, a hexo blog can be built with just few commands. It has markdown support, which is also a simple but powerful mark language. Hexo and other static blog framework, such as jekyll, parses posts with markdown or other render engine and generates static files (seems not only html) with beatutiful themes. The user don’t need to be an expert on web design to have a fancy indie blog. However, the most important thing for me maybe keep writting blogs.

Hexo

To build a hexo blog, some tools are essential, i.e., node.js and git, then hexo, see the official guide. It would not take ten minute for a linux or mac to get all ready. Then just make a directory, where the Hexo blog will be, execute the following command to initialze a blog.

$ hexo init
$ npm install

Now the floder includes some folder and files. The _config.yml configures most options of Hexo, and markdown posts will be in source folder. Then execute

$ hexo generate

to generate the static web files. To see what created, raise up the server on local computer,

$ hexo server

open the web browser and go to http://localhost:4000. To put the website on Internet, see the deployment.

One problem I encountered is that “node command not found”, this is because in linux or mac, the Node.JS executable is named as nodejs rather than node. Make a symbol link would solve the problem.

$ ln -s /usr/bin/nodejs /usr/bin/node

The full documentation of Hexo.

Openshift

Openshift is an open cloud application platform by Red Hat. Up to three applications can be built with a free account. Follow this blog tutorial, the Hexo blog can be built using Nginx server. Actually, I have no knowledge about Nginx, and just followed the tutorial step by step. Maybe other web server can be used. Fortunately, I succeeded to upload website to openshift. The rhc client tool for openshift is really easy to use, which can be installed with gem

$ gem install rhc

Then execute rhc setup to setup client tool.

Once the openshift application is created, the application code repository can be cloned to local computer. The Hexo deployer for Openshift does not work on my computer, as it is complained that in deployer/openshift.js, [error] TypeError: Arguments to path.join must be strings. Thus to upload hexo generated static files, I have to copy all the files generated in Hexo’s public folder to Openshift application’s diy folder. That finally makes this blog.

Update

Picture

To use image in hexo, it is similar to use link in markdown, put ![image caption](image link), the image link can be two types,

  • Local path: create a img folder in …/hexo root/source/, where the image will be located, and use /img/image name as image link.

  • Internet URL: use other cloud storage service, such as Dropbox, or Qiniu. Upload image to the cloud drive, and use the generated image url. Use hexo’s tag to add image.

    • Add imbed.js in …/hexo root/scripts
    hexo.extend.tag.register('imbed', function(args, content){
    var id = args[0];
    return 'http://your_bucket_url';
    });
    • Use img tag in markdown.
    ...
    <img src="{% imbed %}/sub_folder_name/image_name">
    </img>
    ...

For example,

Math

The default hexo does not contain TeX parser, but MathJax can be added. Also, there is a plugin, hexo-math to make this even easier.
MathJax Inline

Simple inline $a = b + c$.

Always use \ to escape special character for inline mode, or use hexo-math’s tags to avoid the hard way.

MathJax Block

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

Tag Inline

This equation {% math \cos 2\theta = \cos^2 \theta - \sin^2 \theta =  2 \cos^2 \theta - 1 %} is inline.

Tag Block

{% math-block %}
\begin{aligned}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{aligned}
{% endmath-block %}

And the Bayes rule.
$$
\Pr(A_i \mid B) = \frac{\Pr(B \mid A_i)\Pr(A_i)}{\sum_j\Pr(B\mid A_j)P(A_j)}
$$

PS: Move back to github pages, the git deployer can upload the contents perfectly.
PPS: Update Hexo to 3.x and use NexT theme, no need to use hexo-math.