How I built this blog site

How I built this blog site

Clark Frankfurt, Germany

💡 Hexo is a straightforward and fast blog static site framework with various themes you can select from. The following will introduce how I build this blog site with Hexo and hexo-theme-cactus.

1. Prerequisites

1
2
$ brew install node
$ brew install git

– For Linux

1
2
3
$ sudo apt update
$ sudo apt install nodejs
$ sudo apt install git

2. Quick Start with Hexo

2.1. Installing Hexo

1
$ npm install hexo-cli -g

2.2. Setting up Hexo locally

1
2
3
$ hexo init ~/blog
$ cd ~/blog
$ hexo server
  • Now, you can visit your basic Hexo blog at http://localhost:4000. Hexo will watch for all file changes and automatically render the site. You can press Ctrl+C to stop the server.

2.3. Posting your first blog

1
$ hexo new post "my first post"
  • Restart the hexo server, and you will see your first post!

2.4. Let’s write something

  • Before writing the first blog, let’s take a look at the Hexo file structure.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ tree -L 3

|-- _config.landscape.yml
|-- _config.yml
|-- db.json
|-- node_modules
|-- package-lock.json
|-- package.json
|-- scaffolds
|-- source
| `-- _posts
| |-- hello-world.md
| `-- my-first-post.md
`-- themes
  • As we can see, the new post “my first post” has been created inside the source/_posts folder, and all of your posts will be stored in this folder if not assigned categories. By default, Hexo has created a hello-world.md tutorial post for us.
  • Now, you can add any content to this new post.
1
2
3
4
5
6
7
8
9
$ vim ~/blog/source/_posts/my-first-post.md

---
title: my first post
date: 2022-08-21 00:50:27
tags:
---

Ciao! This is my first Hexo blog post!
  • Press Esc and then type :wq to quit Vim. Restart Hexo server and refresh http://localhost:4000, you will see the post.

2.5. Generating static files

1
$ hexo generate 
  • All static files will be generated under /blog/public/ folder.

3. Changing the theme

3.1. installing hexo-theme-cactus

1
2
$ cd ~/blog
$ git clone https://github.com/probberechts/hexo-theme-cactus.git themes/cactus

3.2. Setting the Theme

  • Modify the value of theme: in _config.yml file to cactus, and restart Hexo server.
1
2
3
4
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: cactus
1
$ hexo server

3.3. configuration

  • Most of the site settings can be found in the _config.yml file.
1
2
3
4
5
6
7
8
# Site
title: Magic Cat
subtitle:
description: Not done yet, I\'m trying
keywords:
author: Clark
language: en
timezone: ''
  • More theme detail settings can be found in ~/blog/themes/cactus/_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
projects_url: https://github.com/username/username.github.io
direction: ltr
nav:
home: /
about: /about/
articles: /archives/
Gallery: /gallery
Archives: /
Search: /search/

social_links:
github: https://github.com/username
...
# Available color schemes are 'dark', 'light', 'classic' and 'white'.
colorscheme: light
...

4. Deploying Hexo blog on Github Pages

4.1. creating a repository

1
2
$ cd ~
$ git clone https://github.com/username/username.github.io
  • Generating Hexo public files
1
2
3
$ cd ~/blog
$ hexo clean
$ hexo generate
  • Copy all the files generated under ~/blog/public to ~ @/username.github.io
1
$ cp -r ~/blog/public/* ~/username.github.io/
  • Push it
1
2
3
4
$ cd ~/username.github.io/
$ git add .
$ git commit -m "Initial commit"
$ git push -u origin main
  • Wait for a few minutes, then go to username.github.io on a browser, you can see your new blog on Github Pages, and you’re done!

4.2. One-command deployment

  • Hexo provides a more straightforward way to deploy your site. First, install hexo-deployer-git
1
2
$ cd ~/blog
$ npm install hexo-deployer-git --save
  • Next, add configs to the bottom of the _config.yml file as follows.
1
2
3
4
deploy:
type: git
repo: https://github.com/<username>/<project>
branch: main
  • Then, run:
1
$ hexo clean && hexo deploy
Comments