Creating a Blog by Hexo

Have you ever wished you could create your own blog in no time? Did you get frustrated as you thought you might not have enough time to design and set it up? Do you also wish to have more control over your blog comparing to other blogs such as those in WordPress?

Well, that was exactly the case for me and if it’s the same for you, then give “static site generators” a go.

What is a “Static Site Generator”?

In short, a static site generator is basically a HTML file generator. It crates and formats HTML files by using its template engine as well as your text which is usually in a format such as markdown.

Static site generators are very much easy to setup and use while providing users with more control over it. You can choose and heavily customize themes, choose among plenty of plug-ins and finally host your website on Github pages for free.

What is Hexo?

According to Hexo’s documentation, Hexo is a fast, simple and powerful blog framework. You write posts in Markdown (or other languages) and Hexo generates static files with a beautiful theme in seconds.

-Alright, now let’s dive in.

Installing Hexo

Before installing hexo, use your OS package manager to update and cleanup system packages.

$ brew update --all && brew upgrade --all && brew cleanup && brew doctor && brew prune

Install Node.js

Hexo is a node.js package. As a result, we first need to install the node.js in case it’s not.

$ brew install node

On Linux machines, the procedure is similar with the distro’s package manager. On Windows machines, please refer to this page for download.

npm is the default package manager of the node.js. In case you have had the node installed for some time, make an update and clean the previously installed packages. We will later on use npm to install all the required packages in our blog.

$ npm update && npm upgrade && npm cache clean

Now, we can actually install the Hexo package.

$ npm install hexo-cli -g

Creating Your First Blog

Now, in order to create a blog, goto a directory in which you want to create a blog.

$ hexo init blog

After the blog directory is created, change directory (cd) to the created folder and download all the node modules we need to run and manage our blog.

$ cd blog
$ npm install

Running Your Blog server

Now let’s clean (not needed for the first time but it’s a good practice), generate and run the blog on a node server on the default port 4000.

$ hexo clean && hexo generate && hexo server

You can now view your blog locally on your browser.

Creating Post, Page or Draft

In order to create more posts, you simply need to create .md files within your _posts folder. Additionally, Hexo also provides the following sugar coated commands to create a post, page or draft.

$ hexo new "My Post"
$ hexo new post "My Post"
$ hexo new page "About Me"
$ hexo new draft "My Post"

Now that you have a post, open it in your favorite editor and write your content in markdown language. Having a cheat sheet at your disposal is also a good idea while you are writing in Markdown.

At this point you have a working blog (with the default theme). You might want to apply and customize a different theme. Hexo provides a handful of themes on their website that you can choose from. In addition to themes, plenty of plug-ins are also available for hexo that can totally enhance your blog and your reader’s experience form it.

So, if you still eager about improving your blog and connect a couple of useful plug-ins, read further on the next section.

Share Comments