万物之时

万物之时

万物之时的个人博客
github
blog

Building a Hexo Blog 11b9cc4813b98074b198fe92d5bdd910

Hexo Blog Setup#

type: article
status: published
date: 2024/10/10
slug: hexo
summary: Hexo is a fast, simple, and efficient blogging framework. Hexo uses http://daringfireball.net/projects/markdown/ (or other markup languages) to parse articles and can generate static web pages with beautiful themes in seconds.
tags: hexo, blog, website building, text
category: tutorial

What is Hexo?#

Hexo is a fast, simple, and efficient blogging framework. Hexo uses Markdown (or other markup languages) to parse articles and can generate static web pages with beautiful themes in seconds.

1. Software Preparation Before Setup#

Software needed before setup:
Git: Download from the official website: https://git-scm.com/
Git installation tutorial: https://www.cnblogs.com/xueweisuoyong/p/11914045.html
Node.js official download: http://nodejs.cn/
This article has a tutorial on modifying the node.js cache path: https://www.cnblogs.com/liuqiyun/p/8133904.html
If downloading is troublesome, you can download via cloud storage:
Download link for Xiaofei Cloud: (node-v20.18.0-x64, Git-2.46.2-64-bit)
Link: https://share.feijipan.com/s/voCrF8tW

Test if everything has been downloaded successfully

node -v  
npm -v  
git -v  

2. Install Hexo.#

Download Hexo#

npm install hexo-cli -g  

Generate Blog Content Locally#

  1. Create a new folder named Blog in your preferred location, then enter the folder.
  2. Right-click in the blank space and select Git bash here, then enter the following commands:
hexo init  
hexo install  

If prompted with ‘command not found’, prepend with npx, like: npx hexo init

Then enter the following commands:

hexo g  
hexo s  

The connection to GitHub may be unstable in China, so it’s best to use a VPN.

Setting Up a GitHub Repository#

  1. Register/Login to Github
  2. Click Create a new repository to enter the new repository page.
  3. Enter the repository name:
username.github.io  

Note: This must be your GitHub username.

https://cdn.jsdelivr.net/gh/wanwuzhishi/picx-images-hosting@master/Clip_2024-10-07_22-10-04.7p3l109rpo.png

Check Public

Check Add a README file

Scroll down and click create to create the repository.

https://cdn.jsdelivr.net/gh/wanwuzhishi/picx-images-hosting@master/Clip_2024-10-07_22-11-53.361jy16mei.png

Generate SSH Keys#

Enter any folder, right-click in the blank space and select Git bash here, then enter:

ssh-keygen -t rsa -C "email address"  

Here, "email address" is the email you registered with GitHub.

  1. Press Enter four times.
  2. Go to C:\Users\username, and enter the .ssh folder.
  3. Open id_rsa.pub with Notepad, select all and copy the code inside.
  4. Then open github
  5. Go to user settings and find SSH keys.
  6. Create a new SSH key, name it as you like, and paste the code below.
  7. Click create.

Test if Successful#

In git bash, enter:

ssh -T git@github.com  

Press Enter, then type yes.

Deploy Local Blog to GitHub#

  1. Go to the previous Blog folder, open _config.yml with Notepad.
  2. Scroll to the bottom, delete everything after deploy, and copy and paste this segment:
  type: git  
  repository:  
  branch: main  

Pay attention to the indentation format: each line should have two spaces in front, do not delete them, and there should be a space after each colon as well.

  1. Go to the GitHub repository page you created earlier, click code, and copy the https link.
  2. Paste it after repository: in your Notepad.
  3. Then save and exit.

Back to the Blog folder, git bash#

Install the automatic deployment tool:

npm install hexo-deployer-git --save  

Then right-click in the Blog folder to open git bash, and enter:

hexo g (generate)  
hexo d (upload)  

If this is your first time using git, you will need to configure it:

git config --global user.email "your email"  
git config --global user.name "your name"  

After configuring, upload again with hexo d.

Log in in the pop-up window.

https://cdn.jsdelivr.net/gh/wanwuzhishi/picx-images-hosting@master/Clip_2024-10-07_22-33-18.1025ca6otu.png

This successfully uploads the local content to GitHub.

Once the upload is successful, we have completed the setup! Let’s check your website.

The URL is the repository name we set earlier: username.github.io

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.