Verson: 0.0.1

Foreword

This blog post mainly introduces the blog construction and related content based on Hexo and Github Pages.

Environment build

Install Nodejs

  1. Go to the official website to download the latest Nodejs installation package.
  2. Run the installation package to install, note that you need to select Add to PATH in the Custom Setup step.

Install Git

  1. Go to the official website to download the latest Git installation package.
  2. Run the installation package to install.

Verify Nodejs installation configuration

  1. Right click anywhere and select Git Bash Here.
  2. Execute the command node -v and npm -v. If the output information is the version number, it proves that the configuration is successful.

Install cnpm

  1. Execute the command npm install -g cnpm --registry=https://registry.npmmirror.com or npm install -g cnpm --registry=https://registry.npmjs.org in Git Bash.
  2. Execute the command cnpm -v. If the output information is the version number, it proves that the configuration is successful.

Hexo

Install Hexo

  1. Execute the command cnpm install hexo-cli -g in Git Bash.
  2. Choose a suitable location to create a blog folder, open Git Bash in this blog folder and execute the command hexo init. Note that in the mainland network environment, there may be a freeze at Install dependencies. If the installation freezes for a long time, you could execute the command Ctrl+C to end the command Install dependencies, and execute the command cnpm install to continue to use the mainland mirror to complete the initialization of the hexo blog.
  3. Execute the command hexo server to preview the blog. The output URL is generally http://localhost:4000/, which is the preview page for local deployment.

Replace Hexo theme

The Hexo official website provides a large number of Hexo themes for users to choose.

If you want to practice this step of replace Hexo theme, you can choose the Next theme. The Next theme provides preview effects, project addresses and configuration documents, which is quiet easy to grasp.

Download other themes

  1. Open the project addresses of the theme you enjoy, click the Clone or download.
  2. Copy the address started with “https://“.
  3. Open Git Bash in your blog folder and execute the command git clone *address you copied* themes/*theme name*. Here, git clone stands for cloning, followed by the download addresses you just copied. The last themes/*theme name* is to download the folder to the theme directory, and name the theme file “theme name”.

Modify the configuration file to enable the new theme

  1. Open the file named _config.yml in the blog directory.
  2. Find the line themes, and then change the theme name to *theme name* you have just named.

Generate new blog posts

  1. Open Git Bash in your blog folder and execute the command hexo new *your blog name*.
  2. Each generated blog post is stored in source/_posts under your blog folder.
  3. Blog posts are generally markdown-based .md format files. You could further write and revise your blog posts.

Git

Create new repository

Click the Create repository button to create a new repository. The name of new repository must be *your user name*.github.io.

  1. Open Git Bash in your blog folder and execute the command ssh-keygen -t rsa -C "your_email@youremail.com". No matter what message appears, you just need to press Enter.
  2. Execute the command cat ~/.ssh/id_rsa.pub. The secret key is output. You could copy the output key directly.
  3. Click the avatar of your github, click Settings–SSH and GPG keys–New SSH Key.
  4. Paste the secret key you just copied in the key text box. Click the button Add SHH key.
  5. Open Git Bash in your blog folder and execute the command ssh -T git@github.com. The output information will prompt Are you sure you want to continue connecting (yes/no/[fingerprint])?, enter yes, and then press Enter.
  6. Open your repository, click the Clone or download–Use SSH. Copy the address started with “git”. Open site configuration file. Modify deployment information _config.yml.
    1
    2
    3
    4
    deploy:
    type: git
    repo: *the address started with "git" you just copied*
    branch: master
  7. Open Git Bash in your blog folder and execute the command git config --global user.name "yourname" and command git config --global user.email "youremail".

Deploy and upload

  1. Install the upload plugin. Open Git Bash in your blog folder and execute the command cnpm install hexo-deployer-git --save.
  2. Upload. Open Git Bash in your blog folder and execute the command hexo g -d.

Preview

  1. Open Git Bash in your blog folder and execute the command hexo s.
  2. Your local preview version will be running at http://localhost:4000/.

Thanks and Reference