Build a blog based on hexo

This article uses to host our blog on the github page platform. In this way, you can write with peace of mind, without regular maintenance, and hexo, as a fast and concise blog framework, is really easy to build a blog with it.

first part

Hexo's primary construction and deployment to the github page and binding of personal domain names. (Because the bag is shy, I haven't purchased the domain name yet, hehe)

Hexo build steps

  1. Install Git
  2. Install Node.js
  3. Install Hexo
  4. GitHub creates a personal repository
  5. Generate SSH and add it to GitHub
  6. Deploy hexo to GitHub
  7. Set personal domain name
  8. post article

1. Install Git

Git is currently the most advanced distributed version control system in the world, which can handle version management from very small to very large projects effectively and at high speed. It is a tool used to manage your hexo blog posts and upload them to GitHub. Git is very powerful, I think I recommend everyone to find out. Teacher Liao Xuefeng’s Git tutorial is very well written, so you can find out. Git tutorial

windows: Go to the official git website to download, Download git, after downloading, there will be a Git Bash command line tool, and use this tool to use git in the future.

linux: It is too simple for linux, because the earliest git is written on linux, only one line of code is required
sudo apt-get install git

2. Install nodejs

Hexo is written based on nodeJS, so you need to install nodeJs and the npm tool inside.

windows: nodejs chooses the LTS version

After the installation is complete, check

node -v npm -v

3. Install hexo

After the previous git and nodejs are installed, you can install hexo. You can create a folder blog first, and then go cdto this folder (or right-click git bash under this folder to open it).

npm install -g hexo-cli

Still use to hexo -vcheck the version

At this point, all the installation is complete.

Next, initialize hexo

hexo init myblog

You can choose any name for this myblog, and then

cd myblog //进入这个myblog文件夹 npm install

After the creation is complete, there are:

  • node_modules: dependent packages

  • public: store the generated page

  • scaffolds: Some templates for generating articles

  • source: used to store your articles and some other image resources, etc.

  • themes: theme

  • ** _config.yml: Blog configuration file**

    hexo g hexo server

Use ctrl+c to turn off the service.

4. GitHub creates a personal repository

First of all, you need to have a GitHub account, so go to register one.

After registering and logging in, you will see a New repository in GitHub.com, create a new repository

Create a warehouse with the same username as yours, and add .github.io at the end. Only in this way will it be recognized when you deploy to the GitHub page in the future, which is xxxx.github.io, where xxx is the user you registered with GitHub name. I have already built it here.

Click create repository.

5. Generate SSH and add it to GitHub

git config --global user.name "yourname" git config --global user.email "youremail"

Here yourname enters your GitHub username, youremail enters your GitHub mailbox. This way GitHub can know if you correspond to its account.

You can use the following two to check if you lose right

git config user.name git config user.email

Then create SSH, press Enter all the way

ssh-keygen -t rsa -C "youremail"

At this time it will tell you that the .ssh folder has been created. Find this folder on your computer.

ssh, to put it simply, is a secret key, among which id_rsa is the private key of your computer and cannot be shown to others, and id_rsa.pub is the public secret key, which can be shown to others. Put this public key on GitHub, so that when you link to GitHub's own account, it will match your private key according to the public key. When it matches with each other, you can successfully upload your files to GitHub via git .

Then in the GitHub setting, find the SSH keys setting option, click New SSH key
to copy the information in your id_rsa.pub.

ssh -T [email protected]

6. Deploy hexo to GitHub

In this step, we can associate hexo with GitHub, that is, deploy the article generated by hexo to GitHub, open the site configuration file _config.yml, turn to the end, and modify it to
YourgithubName is your GitHub account

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

At this time, you need to install deploy-git first, which is the deployment command, so that you can use the command to deploy to GitHub.

npm install hexo-deployer-git --save

hexo clean hexo generate hexo deploy

Among them, hexo clean clears the things you generated before, and deletes the static pages generated before (related to public files)
hexo generate As the name suggests, generate static articles, you can use hexo g abbreviation
hexo deploy to deploy to github, you can use hexo d abbreviation

Note that you may be required to enter your username and password when deploying.

The following figure shows that the deployment is successful, and you can see your blog on http://yourname.github.io in a while! !

7. Set up personal domain name

Now the address of your personal website is yourname.github.io, if you feel that this URL is not enough to be forced, you need to set up a personal domain name. But it costs money.

Then this is the blog I successfully built
:

https://blog.csdn.net/sinat_37781304/article/details/82729029

Guess you like

Origin blog.csdn.net/qq_43458555/article/details/107978671