抹桥的博客
Language
Home
Archive
About
GitHub
Language
主题色
250
609 words
3 minutes
Building a Blog with Hexo and GitHub

It took me two days, but I finally got my blog set up. I encountered many issues along the way, but thankfully, the mighty Google helped me resolve each one. Now I’m writing down the process, hoping to help others who might need it, just like I did.

Framework Selection#

When I first decided to build a blog, the initial thought was to consider what type of website I wanted: a dynamic site or a static site. Given that I just wanted a space to record my thoughts, I opted for a static site. There are many frameworks available for static sites, including Jekyll (recommended by GitHub), Octopress (developed based on Jekyll), and Hexo (written using Node.js).

Jekyll#

Jekyll is a simple, blog-aware, static site generator. It takes a directory containing raw text files in various formats, such as Markdown (or Textile) and Liquid, and renders them into a complete, publishable static website that you can host on any server you like. Jekyll can also run on GitHub Pages, meaning you can use GitHub’s service to build your project pages, blog, or website, completely free of charge.

I originally intended to use Jekyll, but I encountered several issues during configuration. Installing Jekyll on Windows repeatedly failed, and after numerous attempts to find a solution, I eventually gave up.

Octopress#

Octopress is a blogging system developed using the Jekyll blog engine. The static pages it generates display very well on GitHub Pages. It’s touted as a blogging system exclusively for hackers (A blogging framework for hackers.).

Hexo#

Hexo is a fast, simple, and powerful blog framework powered by Node.js. Compared to Jekyll, it’s faster and more lightweight. It was created by Taiwanese university student tommy351, and can compile hundreds of articles in just a few seconds. The static web pages generated by Hexo can be directly deployed to platforms like GitHub Pages, BAE, SAE, and others.

Because of its compactness, ease of configuration, and equally powerful features, I ultimately chose Hexo.

Environment Setup#

You’ll need to install Node.js, Git, and an editor. You can find the official websites for these and follow the installation instructions.

Installing Hexo#

Once the above software is installed, simply execute the following command:

npm install -g hexo

Initialization#

Execute the init command to initialize Hexo into your specified directory. For example, I’m using the blog folder on my D drive (all subsequent commands will assume this path):

D:\blog>hexo init

The installation process is complete. Wasn’t that simple?

Generating Pages#

D:\blog>hexo generate

Local Startup#

D:\blog>hexo server

Enter http://localhost<4000> in your browser, and you’ll be able to see your own blog.

Writing Blog Posts#

Execute the new command:

D:\blog>hexo new [layout] "postName"#其中layout为模版类型,默认为post,“postName”为你的文章名

You can then find the corresponding file in hexo\source\_posts\, and start writing your article.

Deployment#

You can choose GitHub Pages, which offers 300MB of free space and unlimited traffic. The method is also very simple: create a username.github.io repository under your GitHub account, then in the _config.yml configuration file located in your Hexo directory:

deploy:
deploy:
  type: github
  repository: https://github.com/kisnows/kisnows.github.io.git
  branch: master
  #此处将kisnows替换为你的github账号名

And that’s all there is to it!

Common Commands#

hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录 简写:hexo g
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server) 简写:hexo s
hexo deploy #将.deploy目录部署到GitHub 简写:hexo d
hexo d -g #组合命令,先生成页面,后部署到Github

This article was published on January 9, 2015 and last updated on January 9, 2015, 3923 days ago. The content may be outdated.

Building a Blog with Hexo and GitHub
https://blog.kisnows.com/en-US/2015/01/09/hexo-blog/
Author
Kisnows
Published at
2015-01-09
License
CC BY-NC-ND 4.0