Step-by-Step: Using Hexo and GitHub to Create Your Website
Hi everyone! I’m excited to share that I’ve created my own website today! Welcome to my blog!
In this post, I’ll share my step-by-step approach to using Hexo and GitHub to build it.
1. Preparation
GitHub Account
You’ll need a GitHub account. If you don’t have one, head over to the official website http://github.com to register.
Install Git
Install Git on your computer. I used homebrew for installation.
Install Node.js
Install Node.js on your computer. You can also use homebrew for this installation.
2. Create Repository
To set up your website:
Create Repository: Go to your GitHub account and navigate to “Your repositories” to access the repositories page. Create a new repository named
<username>.github.io
.Create Homepage File: Within this repository, create a new file named
index.html
. This file will serve as the homepage for your website.Add Content to Homepage: Populate the
index.html
file with some basic content. For instance:1
2<p>Hello</p>
<p>I'm xxx, and this is my personal website.</p>Commit Changes: After adding content, click “Commit new file” to save these changes to the repository.
Access Your Homepage: Your newly created homepage’s address can be found in GitHub Pages at https://[your_username].github.io/
3. Configure SSH
To enable remote file uploads from your computer to your GitHub repository, configure SSH by following these steps:
- Click on your personal GitHub account’s “Settings” option.
- Navigate to “SSH and GPG keys” to configure your SSH public key.
4. Blog Initialization
We’ll use Hexo to create your blog website. Hexo is a static blog site generator based on Node.js. You can find its official website at https://hexo.io.
Create an empty folder, for instance, github_blog
. Use the hexo init
command to initialize your blog. The contents of the initialized folder are described as follows:
_config.yml
: Configuration information for the website, where you can set most parameters.package.json
: Application information.scaffolds
: Folder for templates. Hexo uses these to create files when you create a new post.source
: Folder for resources.themes
: Folder for themes, which Hexo uses to generate static pages.
5. Generating Your Personal Blog Website
Edit the _config.yml
file with the following deployment information:
1 |
|
After installing the plugin npm install hexo-deployer-git --save
, run the following commands:
1 |
|
At this point, your blog data will be pushed to GitHub. The empty repository created in the first step will now have content. You can access your website at https://username.github.io/, where ‘username’ is your GitHub username.
6. Create a New Post
Let’s create a blog post titled “Hello world!” using the following command:
1 |
|
This will generate a Hello world!.md
file in the source/_posts
folder within your current directory. The file will have the following content:
1 |
|
After the ---
, you can write the content of your blog post using Markdown format.
Once you’ve finished writing your blog post, use the following commands:
1 |
|
This will update your personal blog with the newly added post.
I hope this guide helps you. Happy website building!