banner
阿道

阿道

阿道博客

Build a Static Blog for Free on Github from Scratch - Hexo Tutorial

The tutorial demonstration environment is macOS, and the steps for Windows are basically the same, so I won't elaborate further here.

Installation Preparation#

Before installing Hexo, you must ensure that the following two software are already installed on your computer:

  • node.js
  • git (it will prompt for installation, just agree)

Start Installation#

  1. Open the terminal tool and enter the following command to gain administrator privileges:
   sudo su
  1. Install npm. Due to special circumstances in China, installing npm can be quite slow, so we will use Taobao's cnpm for installation:
npm install -g cnpm --registry=https://registry.npm.taobao.org
  1. Install Hexo:
cnpm install -g hexo-cli
  1. Check if you are in the user directory; if so, continue. Otherwise, you need to enter the user directory first (usually the folder with your username).

  2. Create a new directory; I will name it blog:

mkdir blog
  1. Enter the blog directory:
cd blog
  1. Initialize the blog:
sudo hexo init

Tip: INFO Start blogging with Hexo! indicates success.

  1. Local testing:
hexo s

Displays
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.

  1. Open the above address in a browser to view the Hexo blog.

Default Title_2019-07-18-0

Publish a New Article#

  1. Create a new article:
hexo n "Article Title"

INFO Created: /Users/ching/blog/source/_posts/Article Title.md

  1. Enter the article (here I will directly use the vim command to edit, of course, you can also use other Markdown editors).

  2. Press i and then Enter to edit; I will just input some content randomly. After editing, press Esc and type to save.

  3. Return to the blog directory and clean up:

hexo clear
  1. Generate website content:
hexo g
  1. Use the hexo s command again to start local testing and check if the publication was successful.
    Snipaste_2019-07-25_19-07-32

Publish Local Website to the Internet#

Today we will demonstrate how to publish the website to GitHub.

  1. Log in to GitHub.
  2. Create a new repository:
  • Click the + icon in the upper right corner and select new repository.
  • Repository name: GitHub username + github.io.
  • Fill in the description.
  • Click create repository to create it.
  1. Return to the local terminal and install the plugin hexo-deployer-git:
cnpm install --save hexo-deployer-git
  1. Open the configuration file:
vim _config.yml
  1. Move to the end of the document and edit:

deploy:
type: git
repo: https://github.com/username/custom_address.github.io.git
branch: master

  1. Deploy to GitHub:
hexo d

Enter GitHub account password, and display INFO Deploy done: git indicates success.

  1. Log in to our website to view it.
    Snipaste_2019-07-25_19-55-13
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.