Home  >  Article  >  Development Tools  >  How to deploy a blog website using Hexo and Github Pages

How to deploy a blog website using Hexo and Github Pages

PHPz
PHPzOriginal
2023-04-06 08:51:20775browse

Hexo is a static website generator based on Node.js, which can help you quickly build your own blog website. Github Pages is a static website hosting service provided by Github, allowing you to deploy your website to Github.

In this article, we will discuss how to use Hexo and Github Pages to deploy your own blog website.

First, make sure you have Node.js and Git installed. If you haven't installed it yet, you can go to the official website to download and install it.

Next, we need to install the Hexo command line tool. Open a terminal and run the following command:

npm install hexo-cli -g

This will install the Hexo command line tool globally.

Next, create a new Hexo site in the terminal and run the following command:

hexo init myblog

cd myblog

npm install

This will create a new site called myblog and install all dependencies.

Now, we need to deploy our Hexo site to Github Pages. First, create a new repository named username.github.io on Github, where username is your Github username.

Then, execute the following command in the terminal to deploy our site to Github Pages:

npm install hexo-deployer-git --save

This will install Hexo’s Git deployer plugin. Next, we need to configure the deployment settings to our new repository.

Open the _config.yml file of our Hexo site and modify the deploy paragraph to the following content:

deploy:
  type: git
  repo: git@github.com:username/username.github.io.git
  branch: master

Among them, username should be replaced with your Github username. The branch here defaults to the master branch, but you can also modify it to other branches.

Next, run the following command in the terminal to publish our blog:

hexo clean
hexo generate
hexo deploy

This will clear out the old generated files, regenerate the new static files, and push them to our In the Github Pages repository.

Now our blog has been deployed to Github Pages! Open a browser and enter https://username.github.io in the address bar to visit our blog.

To summarize, it is very convenient to use Hexo and Github Pages to deploy your own blog website, and it only takes a few simple steps to complete. I hope this article can help you quickly build your own blog website.

The above is the detailed content of How to deploy a blog website using Hexo and Github Pages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn