在Debian10服务器上搭建博客网站(2)——博客搭建以及遇到的问题(Building a blog website on Debian 10 server (2) — blog building and problems encountered)

0.前言

让我们接着上一篇来看看接下来该怎么利用hexo和github来进行博客的搭建。以及作为笔记记录一下在这个过程中我遇到的问题。

1.创建仓库

在搭建博客之前我们需要创建一个github仓库,在github.com中找到New repository或是在点击头像下方的Your repositories后点击绿色的New图标都可以进行仓库的创建。

取名为你的github用户名后加.github.io,如我的用户名为张三;就取名为张三.github.io。创建仓库后默认会给你生成一个名为main的主分支,如果勾选了创建readme文档可能还会多生成一个文档,这边我们创建完直接不管别的,进入下一步。

2.使用Git以及配置SSH

在这里我们需要对SSH进行配置,我们打开git bash或者直接打开终端。

你可以通过输入以下命令确认有没有输入错误,

然后我们创建一个SSH公钥用于和github的SSH连接,在终端输入:

它会提示你在.ssh文件夹里生成了SSH公钥,我们只需要cd进.ssh文件夹里 然后用cat命令查看并复制下id_rsa.pub里的公钥内容

git config --global user.name "这里改为你的github用户名"
git config --global user.email "这里改为你注册github用的邮箱"
git config user.name && git config user.email
ssh-keygen -t rsa -C "这里改为你注册github用的邮箱"

我们回到github,然后点击头像再点击setting,找到SSH and GPG keys的选项,新添加一个SSH key,把刚才复制的内容粘贴进去,然后点一下Add SSH key之类的选项就能添加了。

回到我们的bash输入测试一下是否成功,成功的话就可以进行下一步了。

ssh -T git@github.com

3.将hexo部署到github

我们要先用npm安装deploy-git,后面操作会用到。(安装过程中有提示需要修复之类的照做就行,如果提示要升级npm版本就不理它)

接着我们cd进blog的文件夹,用vim打开_config.yml文件,把最后的几行修改一下。

npm install hexo-deployer-git --save

repo后面填的内容建议直接在你github的xxx.github.io的仓库页面里点击一下code,然后把弹出的HTTPS的链接复制粘贴过去。

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

然后我们输入以下几行命令

hexo clean
hexo g
hexo d

如果在hexo d之后报错了,可以尝试修改_config.yml把repo:后面改成git@github.com:你的github名字/你的github名字.github.io.git。

我的建议在是你github的xxx.github.io的仓库页面点一下code按钮,再点一下SSH复制里面的链接。

修改完文件后我们再执行一次

hexo clean
hexo g
hexo d

在hexo d的时候可能要输入你的github用户名和密码。

出现INFO Deploy done: git就说明部署成功了,过一会就可以在http://你的github名字.github.io看到你的博客了。

4.小结

这也是我折腾了一下午的一点小记录,感谢fangzh大佬的博文,我基本上是靠着大佬的博文才搞出来了我自己的博客。这一次随笔因为懒的原因就暂时不配图了,等下次再说吧。
先这样了,晚安!

————————

0. Preface

Let’s continue with the previous article to see how to use hexo and GitHub to build a blog. And take notes of the problems I encountered in the process.

1. Create warehouse

Before setting up a blog, we need to create a GitHub repository in GitHub You can create a warehouse by finding a new repository in. Com or clicking the green new icon after clicking your repositories under the avatar.

Name it your GitHub user name followed by github. IO, if my user name is Zhang San; It was named Zhang San github. io。 After creating a warehouse, a main branch named main will be generated for you by default. If you check create readme document, another document may be generated. After we create it, we will go to the next step.

2. Use GIT and configure SSH

Here, we need to configure SSH. We can open git bash or directly open the terminal.
You can confirm whether there is any input error by entering the following command,
Then we create an SSH public key for SSH connection with GitHub, and input the following at the terminal:
It will remind you that you are SSH public key is generated in SSH folder. We just need to CD it in SSH folder, and then use the cat command to view and copy the ID_ rsa. Public key content in pub

git config --global user.name "这里改为你的github用户名"
git config --global user.email "这里改为你注册github用的邮箱"
git config user.name && git config user.email
ssh-keygen -t rsa -C "这里改为你注册github用的邮箱"

Let’s go back to GitHub, click the avatar and then click setting to find the SSH and GPG keys option, add a new SSH key, paste the content just copied, and then click Add SSH key and other options to add it.

Go back to our bash input to test whether it is successful. If it is successful, we can go to the next step.

ssh -T git@github.com

3.将hexo部署到github

We need to install deploy git with NPM first, which will be used later. (if you are prompted to repair during the installation process, just do it. If you are prompted to upgrade the NPM version, ignore it)
Then we put the CD into the blog folder and open it with vim_ config. YML file, modify the last few lines.

npm install hexo-deployer-git --save

The content filled in after repo is recommended to be directly in your GitHub’s xxx github. Click code on the warehouse page of IO, and then copy and paste the HTTPS link that pops up.

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

Then we enter the following lines

hexo clean
hexo g
hexo d

If an error is reported after hexo D, you can try to modify it_ config. YML change repo: to git@github.com : your GitHub name / your GitHub name github. io. git。

My suggestion is your GitHub XXX github. Click the code button on the warehouse page of IO, and then click the link in SSH copy.

We’ll do it again after modifying the file

hexo clean
hexo g
hexo d

You may need to enter your GitHub user name and password when hexo D.

If info deploy done: git appears, the deployment is successful. After a while, you can enter your GitHub name at http: / / www.github.com github. I saw your blog.

4. Summary

This is also a little record of me tossing about all afternoon. Thank fangzh for his blog. I basically relied on his blog to get my own blog. This time, the essay doesn’t match the picture for the time being because of laziness. Let’s talk about it next time.
First, good night!