Use Hexo+Github Pages to build a private blog (the third stop for fun private blogs)

I love three things in this world. Sun, moon and you. Sun for morning, moon for night, and you forever
. The day of the day, the moon of the night, your eternity.

My blog, if I don’t see it for a day, I still miss it.

Haha, the editor is fine and compiled a few old sayings, which are not very good, please forgive me.

Next, the editor will start to talk about the follow-up of the blog (the first two are visible at the bottom of the article). Yesterday we have successfully run the blog locally, so how can we let others access our blog?

1. Deploy the blog to Github Pages.

First, we need a Github account. If you don’t have one, you can register on the official website (https://github.com/). After registration, we need to click the ➕ number on the upper right on our Github to create a new repository (New repository ), we need to pay attention to some things when creating a new repository, as follows:

Insert picture description here
After the repository is built, we can start to configure the SSH key . Only after the SSH key is configured, we can synchronize the local code base with the Github code base through Git operations. Use Git in your first new blog file. Open Bash Here, enter the following command:

ssh-keygen -t rsa -C "your [email protected]" 
//引号里面填写你的邮箱地址,比如我的是*********@qq.com

Then the following page will pop up (in the meantime, press Enter until the key pattern appears):

Insert picture description here

Then enter the following command to copy the key (note the spaces):

clip < ~/.ssh/id_rsa.pub

2. Configure SSH keys on Github

Log in to GitHub, click the image in the upper right corner, and enter Settings;

Find and click SSH and GPG Keys on the left ;

Then click New SSH key;

Paste the key in the key area and write any key title (such as blog key).

3. Test run

We continue to enter the following command in Git (the command does not need to be changed):

ssh -T [email protected]

After running the command, we will see the following page:
Insert picture description here
Then we enter yes, when the following page appears, the configuration is successful.
Insert picture description here
Wow, it feels getting closer and closer to success, hehe.

4. Configure information on Git

Git will record the submission according to the user's name and email address. GitHub also uses this information for permission processing, so we need to enter the following command to set the information, change the name and email address to your own, the name may not be the name of GitHub , But in order to facilitate memory, it is recommended to be consistent with GitHub.

Enter the following command:

git config --global user.name "此处填你的用户名"
git config --global user.email "此处填写你的邮箱"

5. Configuration file information

Open the repository on Github as follows. And click the small symbol to the right of Code, click Use SSH, and then click copy next to it (circled in red)

Insert picture description here
Then open the Hexo folder and find the file circled as follows (right-click to open it with Notepad):
Insert picture description here

To: The above file can also be opened with an editor, such as Sublime.

Turn the config.yml file to the back and find the following configuration:
Insert picture description here
except for the copy part, the rest can be changed to the same as the editor. (Note that there is a space after the colon:, and you need to enter English: Oh, otherwise you may get an error. Also need to pay attention to the indentation, remember not to modify the position of the sentence at will, otherwise you will be at your own risk)

6. Push the blog files to Github

Finally, we need to push the file to Github, right-click in the Hexo file to open Git Bash Here, and enter the following command:

hexo g
hexo d

Or directly enter:

hexo g -d

In the future||We will enter before each push:

hexo clean //清理缓存,以便每次修改后效果能尽快展现

So the editor now uses it directly:

hexo clean && hexo g -d

Now enter hexo g -d. If you are asked to enter your github account and password after execution, then your blog file has been deployed to Github.

If an error is reported, and the error is:
Insert picture description here

Then it means that your deployer has not been installed successfully. You need to enter the following command to install:

npm install hexo-deployer-git --save

Another thing to note on Github is that the circled part must be Branch: master. Otherwise, it is easy to report errors.

Insert picture description here

Finally, we can copy the blue part below to the place where the browser enters the link, and then we can view our own blog. Of course, you can also use your own website, such as: https://your username.github.io/. For example, the editor is https://bob0912.github.io/ .

Insert picture description here
Now everyone can visit you through your blog link.

Guess you like

Origin blog.csdn.net/m0_46259251/article/details/108689304