Use GitHub + Node.js + Hexo build personal blog

Benpian own course record at a time to build Hexo blog platform. (2019.9.13 measured valid)

GitHub

Register an account

Because the article is to build a personal blog service platform based on GitHub, so first of all is a registered GitHub, of course Have an account skip this step;

Create a Repository

Click start, jump to Create a new repository, here is the naming Repository name username.github.io, where username is the username when you register.

 

usename must change the account name, do not change the other, otherwise https://growvv.github.io/rogn.github.io/ this embarrassing situation arises!

Settings

After clicking Create a page to jump into the project, then we clicksettings

Then we drag the page down page, find GitHub Pages, and then click Choose a themeto select the page theme, here we temporarily select the default theme (because later I will replace NexT theme), and then click Select theme.

GitHub Page

Click to select the theme, the page will jump to the Repository can be said to be the home page of it, as shown below. There are reminded to replace the theme above, there are also generate a index.md/markdownfile. Then we go to just settingset in just to see the GitHub Pagesother side, there will display your url, this is your future blog "build" on the URL.

  Then click on the url to access the personal blog is your future will show the way

 

Node.Js

Download and install

Portal: nodejs , select the corresponding version download, install, then it is little point here is not in the narrative.

 After the software installation is complete, open the cmd interface, input node -vand npm -v(pay attention to see if the environment variable part has been correctly), check which version to confirm whether the installation was successful.

 

Git

Download and install

Portal: git , select the corresponding version to download and install. The installation process is not described here, you little point.

After the installation is complete, you may have to manually add the environment variable, right, look versiongit --version

 

 Installation Hexo

At the command line, type:

npm install -g hexo-cli

 After you create a folder (build a blog related files stored here), here I named test (can be self-named), open cmd (in the path of the folder in the input box cmd in the folder path and back car), or in cmd switch directly to the folder, type:

hexo init

(Before executing this command, you must ensure that the folder is empty

If this command is broken, see the last paragraph of this article.

Look after the operation, which at the time of downloading the default theme landscape, there have been some garbled, but not these problems, the last display add add success on the line:

 

 At this folder something more than the following:

 

Running locally

At this point or enter cmd in the folder path in the (-p 5000 represents the set port 5000; if not write this, the default is 4000, but the situation is occupied port number may occur, resulting in pages that can not be opened) :

hexo server -p 5000

Now enter the browser http://localhost:5000/, access to the default interface of the blog:

 

 

In this we can hello_world_blog.mdadd your own blog content file, because I was used as a test, so what the map is not here. Rerun hexo server -p 5000, localhost access can see the page with added content.

Other related commands are as follows:

  • hexo clean Delete public folder and its contents (the contents of public folder content that is uploaded to GitHub Repositoriy of)
  • hexo generate Or hexo g generate content uploaded to GitHub, that public folder
  • hexo deploy Or hexo d uploaded to GitHub (to be configured)

这时候,博客的基本设置(主题设置留待以后)都已弄好,接下来就是解决将博客内容上传至GitHub上的问题。

配置个人信息

打开Git Bash,配置个人信息,分别输入如下命令,yourname即GitHub注册时的用户名,yourEmail即注册时的邮箱账号,以及生成秘钥:

git config --global user.name "yourname"
git config --global user.email "yourEmail"
ssh-keygen -t rsa -C "yourEmail"

需要带上双引号

在秘钥生成后,会有对应的存放文件地址,去该地址中,找到id_rsa.pub文件,复制里面的内容,粘贴至GitHub中,点击右上角用户头像下的Settings,之后点击左侧的SSH and GPG keys,找到New SSH key点击,输入title,并将之前复制的内容粘贴到下面的key中,最后点击Add SSH key,完成:

 

 

 

配置Deployment

去博客总目录下的_config.yml文件中,找到deploy部分,添加如下(yourname就是GitHub的用户名):

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

整体流程

至此,除了博客主题(目前采用默认主题)外,其他基本设置都已弄好。
整体的写文上传等操作流程为:

  1. hexo new newBlog
  2. hexo clean
  3. hexo g
  4. hexo d

 

遇到的问题

hexo d命令报错 ERROR Deployer not found: git

解决方法:

这是因为没安装hexo-deployer-git插件,在站点目录下输入下面的插件安装就好了:

npm install hexo-deployer-git --save

 

 

参考链接:

1. https://asdfv1929.github.io/2017/11/18/hexo-next-blog/

2. https://blog.csdn.net/qq_21808961/article/details/84476504

 

 

Guess you like

Origin www.cnblogs.com/lfri/p/11517723.html