Home > Development Tools > git > body text

How to use github pages to build a personal blog

PHPz
Release: 2023-03-31 11:19:17
Original
1484 people have browsed it

As a programmer, it is very necessary to have a personal blog. In addition to recording your own growth process and technical insights, you can also share your experiences and thoughts with the majority of technology enthusiasts. Nowadays, building a personal blog has become very simple and convenient, because there are many static blog generation tools, which eliminate a lot of tedious work. Among them, using github pages to build a personal blog is highly recommended. Below, we will introduce in detail how to use github pages to build a personal blog.

1. Register a github account

First, we need to register a github account. Github is a very famous code hosting platform, and github pages is a free static web page hosting service provided by github, which can be used to build a personal blog or display your own works. Registering a github account is very simple. You only need to fill in your personal information and email address on the official website.

2. Create a Repository

After registering a github account, we need to create a Repository on github as the code repository for our personal blog. Click the " " button in the upper right corner on the github page, select "New repository", fill in the name and description of the Repository, select whether it is public or private, and then click the "Create repository" button to create a new Repository.

3. Choose a static blog generation tool

After creating the code warehouse on github, next we need to choose a static blog generation tool. Commonly used static blog generation tools include Jekyll, Hexo, Hugo, etc. Here we take Jekyll as an example to introduce. Jekyll is a very popular static website generator and is officially supported by github. It uses Liquid template language, which can help us quickly create a simple and beautiful personal blog.

The installation of Jekyll is very simple, just execute the following command in the command line:

gem install jekyll bundler
Copy after login

After the installation is complete, we can use Jekyll to create a new blog. In a local directory, execute the following command:

jekyll new myblog
Copy after login

where "myblog" is the name of your personal blog and can be customized. After executing the above command, Jekyll will automatically generate a default blog template, which we can pull to github as our own blog code.

The specific steps are as follows:

  1. Upload the local blog folder to the Repository on github

Execute the following commands locally:

cd myblog
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/yourusername/yourusername.github.io.git
git push -u origin master
Copy after login

Among them, "yourusername" is your account name on github, which needs to be replaced with your own account name.

  1. Enter the github page and find the Repository settings

In the Repository settings, find the "GitHub Pages" section and select "master branch" as the Source. If your If the blog folder name is not yourusername.github.io, you need to set it manually.

  1. Wait a few minutes and visit your personal blog

In the "GitHub Pages" section of the Repository, the link to your personal blog will be displayed. After a few minutes, you will be able to access your personal blog through this link.

4. Select a blog theme

Jekyll itself provides some default themes, which can be set in the _config.yml file. However, these default themes may be a bit crude and don't quite meet our requirements. Therefore, we can choose some excellent third-party themes and apply them to our blog.

Jekyll’s third-party themes can be searched and downloaded on Github. After downloading, copy the theme folder to our blog folder, and then configure it in the _config.yml file.

5. Publish blog posts

In the blog folder, we can use Markdown syntax to write blog posts. New blog posts should be placed in the _posts folder, and the file name should be in the format of "year-month-day-article title.md". For example, we can write a blog post named "hello-world" in the _posts directory.

---
layout: post
title:  "Hello World"
date:   2021-09-01 00:00:00 +0800
categories: jekyll update
---

# Hello World

这是我的第一篇博客文章。
Copy after login

The first part is the meta-information of the article, which is used to describe the title, time, classification and other information of the article. The second part is the text content of the article, which is typeset using Markdown syntax.

6. Summary

Through the above steps, we can quickly build a personal blog on github and publish our own blog articles. Using github pages to build a personal blog is not only simple and convenient, but also free and stable. I hope this article can help programmers who want to build a personal blog.

The above is the detailed content of How to use github pages to build a personal blog. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!