Home > Development Tools > git > Discuss how to build a Hexo blog on GitHub

Discuss how to build a Hexo blog on GitHub

PHPz
Release: 2023-04-06 14:03:43
Original
676 people have browsed it

GitHub is a global open code hosting platform that provides developers with a convenient platform for collaboration and code sharing. Hexo is a fast, simple and efficient blogging framework developed based on Node.js. In this article, we will explore how to set up a Hexo blog on GitHub.

  1. Create GitHub repository
    First, we need to create a repository on GitHub. Click New repository on the GitHub homepage, fill in the warehouse name, select Public or Private, and then click Create repository. Next, we need to install Git and use it to push local files to the GitHub repository.
  2. Installing Hexo
    We need to install Node.js and Git locally for subsequent operations. Then open a command line window and enter the following command to install Hexo.
npm install -g hexo-cli
Copy after login
  1. Generate Hexo blog file
    Next, we use Hexo to create a new blog. Enter the following command on the command line:
hexo init myblog
cd myblog
npm install
Copy after login

This command will create a myblog folder in the current directory and install Hexo in it.

  1. Configuring Hexo Blog
    Next, we need to make some settings for Hexo. In the root directory of Hexo, open the _config.yml file. This is the configuration file of the Hexo blog and contains all Hexo settings. We need to configure this file to adjust our personal blog.
  2. Deploy to GitHub Pages
    Hexo automatically generates static HTML files for us, and we need to deploy them to GitHub Pages. Enter the following command on the command line:
npm install hexo-deployer-git --save
Copy after login

This command will install the hexo-deployer-git plug-in to our blog. Then, add the following configuration in the _config.yml file:

deploy:
  type: git
  repository: git@github.com:username/username.github.io.git
  branch: master
Copy after login

where username is our GitHub username. Then, run the following command to deploy the blog to GitHub Pages.

hexo clean && hexo g && hexo d
Copy after login

Hexo will automatically push the blog files to our GitHub Pages page, and we can view our blog by visiting https://username.github.io.

  1. Publish articles
    Finally, we can start publishing our own blog articles. In the Hexo root directory, run the following command to create a new article:
hexo new post "文章名称"
Copy after login

This command will create a new Markdown file in the source/_posts directory, where the "article name" is the The title of the published article.

After running the above command, modify the *.md file under source/_posts/ and write your own article content.

  1. Hexo Theme
    If you want to make your blog more beautiful and personalized, you can change the style of your blog by installing the Hexo theme. Simply run the following command in the root directory of Hexo to install the theme:
git clone https://github.com/author/author.github.io.git themes/theme-name
Copy after login

where author is the GitHub username of the theme author and theme-name is the name of the theme.

Then, in the root directory of Hexo, open the _config.yml file and modify theme to the name of the theme you installed. For example:

theme: theme-name
Copy after login

In this way, you have set up your own Hexo blog, and you can write and share happily.

The above is the detailed content of Discuss how to build a Hexo blog on GitHub. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template