Build your own blog on CentOS, based on Hexo + Next

Prepare environment

Add yum repo

1
2
# yum install -y gcc-c++ make
# curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -

Install node and npm

1
# yum install nodejs

Install git

1
# yum install git

Validate installation

1
2
3
# node -v
# npm -v
# git --version

Hexo site

Install Hexo

1
$ npm install -g hexo-cli

Create and init your site

Creating your site in your own folder

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

Mind the path when run npm install cmd

Site folder

1
2
3
4
5
6
7
8
.
├── _config.yml # Configuration of site(!!)
├── package.json # npm installed packages
├── scaffolds # template files
├── source
| ├── _drafts # Draft pages, omit
| └── _posts # Website original pages
└── themes # Website theme

List generated files to check result

Hello world

1
2
$ hexo generate     # Generate static files
$ hexo server # Start server, default port 4000

Or:

1
2
$ hexo g            # In short
$ hexo s -p <port> # In short, specify port

First blog

Create a new blog(in markdown format), if title contains white space, please use quotes

1
$ hexo new <titile>

It will create a new post with basic tags in path /source/_post

Mind: no need to restart server after new/delete/modify posts

One more step further

Common cmd

1
2
3
4
5
6
7
$ hexo new draft <title>    # Create a new draft(like private posts)
$ hexo publish <filename> # Publish drafts

$ hexo clean # Clean cache and static files
$ hexo deploy # deploy the site

$ hexo list post/page/tag/category # List types

Front-matter

Defines variables of post

1
2
3
4
5
6
7
8
9
10
---
title: Hello World # Title of post(may differ from filename)
date: 2013/7/13 20:46:25 # Create date
tags: # Tags of post, in YAML format
- tag0
- tag1
categories: # Categories of post, in YAML format
- API
- Guide
---

Multi-language support

1
2
new_post_name: :lang/:title.md
permalink: :lang/:title/

When you create a new post, the post will be saved to:

1
2
$ hexo new "Hello World" --lang tw
# => source/_posts/tw/Hello-World.md

and the URL will be:

1
http://localhost:4000/tw/hello-world/

Themes

New theme

Recommend next, or you can find other themes instead

Clone new theme to website folder

1
2
$ cd <folder>
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

Enable this theme in site /_config.yml

1
theme: next

Config theme

Use next as example, others may be found on their website

1
2
3
4
language: zh-Hans               # Set language
avatar: [URL] or under source/ # Set your own avata
favicon: [URL] # Use your own favicon
author: <nickname> # Set your nickname, shown on page

Plugins

Some common plugins may enhance your website

hexo-wordcount Count total words, minutes to read

hexo-admin Provide admin pages to manage hexo site

hexo-generator-search Index pages and provide local search

Reference

Hexo Startup Guide
Next Theme Getting Started