Home > Development Tools > git > Teach you to deploy Hexo to Github

Teach you to deploy Hexo to Github

PHPz
Release: 2023-03-31 14:20:50
Original
2162 people have browsed it

Hexo is a simple and practical static blog generator that we can use to quickly create blogs. It supports a variety of themes and plug-ins, and can easily handle common needs such as Markdown and code highlighting. After writing the blog, we need to deploy it to the Internet to display it to more people, and github is a good choice. Next, let’s explain in detail how to deploy Hexo to Github.

Step 1: Create a Github repository

First, we need to go to the Github official website to create a repository. The naming format is based on "username.github.io".

Step 2: Install Git

Before deploying, make sure Git is installed locally. If not, you can download and install it from the official website.

Step 3: Initialize Hexo

Next, create a folder locally, such as "blog", to store all Hexo files and directories. Run the following command to initialize:

hexo init blog
Copy after login

This command will create a folder named "blog" in the current directory, which contains the base directory of Hexo.

Step 4: Edit the configuration file

In the base directory of Hexo, there is a configuration file named "_config.yml". We need to edit and configure this file. Modify the content of the file as follows:

# Site
title: your-blog-title
subtitle: your-blog-subtitle
description: your-blog-description
keywords: your-blog-keywords
author: your-name
language: zh-CN
timezone: Asia/Shanghai

# URL
url: https://your-username.github.io
root: /

# Deployment
deploy:
  type: git
  repository: https://github.com/your-username/your-username.github.io.git
  branch: master
Copy after login

It should be noted that the contents such as "your-blog-title" and "your-blog-subtitle" need to be changed to the information of your own blog.

Step 5: Install dependencies

Run the following command in the base directory of Hexo to install dependencies:

npm install
Copy after login

Step 6: Generate static files

Execute the following command in the base directory of Hexo to generate static files:

hexo clean && hexo g
Copy after login

This command will generate a "public" directory, which contains all static files.

Step 7: Submit static files to Github

Execute the following command in the base directory of Hexo to submit static files to Github:

hexo d
Copy after login

This command will Upload all static files in the "public" directory to Github.

Step 8: Visit the blog

Finally, enter the following URL in the browser to access the blog:

https://your-username.github.io
Copy after login

Summary

At this point, we Hexo has been deployed to Github. In actual use, if we modify the blog content, we only need to execute the commands in steps 6 and 7 again to submit the updated blog to Github. This method is very simple and convenient, and is suitable for quickly setting up a personal blog.

The above is the detailed content of Teach you to deploy Hexo to 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