← All writing

Creation and deployment of Hexo blog

(Life Reflections) (Code Chronicles) (Wanderlust Notes) NLP Insights (Natural Language Processing Insights) Tech Toolbox (Technical Toolbox) Travel Tales (Travel Stories) Debugging Diaries

阅读中文版 →

(life reflection)
(Code Chronicles)
(Wanderlust Notes)
NLP Insights (Natural Language Processing Insights)
Tech Toolbox
Travel Tales
Debugging Diaries

Preface: Hello everyone, I am the blogger Fathead Minnow. My old computer was retired, which resulted in the content of my previous blog being lost. So, I decided to share how to create a blog and upload the source code to GitHub in the first post of my new blog. Now, let's get started!

Creation and deployment of Hexo blog

Here are the detailed steps to create a new Hexo blog and deploy it to GitHub:

Install pre-installation software

Install Node.js and npm

Hexo is built on Node.js, so first you need to install Node.js and npm (Node package manager). visit Node.js official website Download and install.

Install Hexo

After Node.js and npm are installed, install Hexo globally via npm. Run the following command on the command line:

1
npm install -g hexo-cli

Create a new Hexo blog

Initialize a new Hexo blog

Create a new folder as the root of your blog, then run the following command from the command line:

1
2
hexo init blog
cd blog

This will create a new Hexo blog under the “blog” folder.

Install blog dependencies

Go into your blog directory and run the following command to install the dependencies required for your blog:

1
npm install

Configure your blog

Configure Hexo

Open with your text editor _config.yml file, which is the configuration file for the Hexo blog. you need to url Set to the URL of your GitHub Pages (usually https://<username>.github.io), and you may also want to configure other options, such as the blog's title, description, and author information.

Deploy to GitHub

Install the Hexo deployment plugin

First, you need to install hexo-deployer-git Plugin, this plugin allows you to deploy your blog directly to GitHub. Run the following command from the command line to install:

1
npm install hexo-deployer-git --save

Configure deployment parameters

in _config.yml Add the following configuration to the file:

1
2
3
4
deploy:
type: git
repository: git@github.com:<username>/<username>.github.io.git
branch: master

will <username> Replace with your GitHub username.

Generate static files and deploy

Run the following commands from the command line to generate static files and deploy them to GitHub:

1
2
hexo generate
hexo deploy

Or you can use the following single command to complete both steps:

1
hexo g -d

Add new article

You can use Hexo's new command to quickly create new articles. Run the following command on the command line:

1
hexo new "文章标题"

Replace "Post Title" with your desired post title. This will be in source/_posts Create a new Markdown file in the directory, and the file name is the article title you specified (replace the spaces with -)。

You can open this file with any text editor you like and write your article content inside. Hexo uses Markdown syntax, you can check Markdown syntax manual Come learn how to use Markdown.

Once completed, you can regenerate and deploy your blog, and the new posts will appear on your blog.

Article classification

You can use YAML front-matter in your articles to assign categories and tags to the articles. Prerequisite lessons should be placed at the top of each article, for example:

1
2
3
4
5
6
7
8
9
10
11
12
---
title: 文章标题
date: 2023-07-06 00:00:00
categories:
- 分类1
- 分类2
tags:
- 标签1
- 标签2
---

这里是文章的内容。

In this example, this article is assigned to the two categories "Category 1" and "Category 2", and is also assigned the two tags "Tag 1" and "Tag 2".

When you generate your blog, Hexo will automatically create an index based on these categories and tags, and visitors can find articles through categories and tags.

Save blog source files to GitHub

Create a new GitHub repository

Log in to your GitHub account and create a new repository. You can give this repository any name you like, such as my-hexo-blog. There is no need to initialize README, .gitignore or license.

Initialize Git

In your blog directory, run the following command to initialize Git:

1
git init

Add all files to Git

Run the following command to add all files to Git:

1
git add .

Submit your changes

Run the following command to commit your changes:

1
git commit -m "Initial commit"

Add remote warehouse

Run the following command to add the repository you just created on GitHub as a remote repository:

1
git remote add origin git@github.com:<username>/my-hexo-blog.git

will <username> Replace with your GitHub username.

Push to GitHub

Run the following command to push your blog source files to GitHub:

git push -u origin master

After completing these steps, your Hexo blog will be deployed to GitHub Pages. you can visit https://<username>.github.io Come check out your blog. Every time in the future you want to add a new article, just source/_posts Just add a new Markdown file in the directory, then regenerate and deploy your blog.

In the future, every time you modify the blog source file (such as adding a new post), you will need to run git add .git commit -m "your message" and git push command to update your backup on GitHub.