BUILD Personal Website with Hexo and GitHub Pages
Contents of this documents and quicklinksοΌ
It has been a long time since I would like to own a particular space to record my work and enjoy my hobby of writting, and until now I've finally started creating my personal website here. Among a variety of schemes, I adopt Hexo
+ GitHub Pages
, which is friendly to noob like me.
Hexo is a fast, simple & powerful blog framework. Simply write post in Markdown and Hexo generates static files deployed to GitHub Pages.
As the first post, I am writing this article just in case anyone who is also interested in having a personal website but hasn't been prepared yet. On the other hand, it will be an importent reference for myself to re-create the environment efficiently when I change the Mac or migrate data in the future.
Node.js
locallyNode.js
is a free, open-source, cross-platform (Mac OS, Window, Linux), and JavaScript runtime environment that lets developers create servers, web apps, command line tools and scripts.
Navigate to Node.js webpage and select the appropriate installation file to download according to your local environment.
After the installation is complete, enter the following commands in the terminal:
If there are output with version numbers, the installation of Node.js is successful in your local computer.
Git is a distributed version control system that tracks versions of files. It is often used to control source code by programmers who are developing software collaboratively.
If you are not familiar with Git, or you have heard of Git but want to know more about it, you can come to the lesson materials from CodeRefinery
Following the instructions HERE to install Git.
After the installation, right-click the mouse anywhere on your desktop or in a folder. If you see the following options:
Open Git GUI here
Open Git Bash here
then Git has been successfully installed on your computer.
Hexo is a fast, simple, and powerful blogging framework powered by Node.js. It allows users to create static websites, blogs, or portfolios with minimal setup. Hexo uses Markdown files for content, which makes it easy to write posts, and it generates static HTML files, which makes it fast for hosting.
Moreover, Hexo provides many themes that you can easily integrate to your blog with a full of customization.
Once Node.js and Git are successfully installed, you can use npm (Node Package Manager) to install Hexo:
Once Hexo is installed, run the following commands to initialize Hexo in the target <my-website>
.
This will creates a new directory (<my-website>
) with the default/essential structure of a Hexo site and installs the required dependencies. Your project folder will look like:
_config.yml
is the "site config" file in Hexo root dict, personalize the top contents like title
, subtitle
, author
, description
and other global settings.package.json
file contains the application data. The EJS, Stylus and Markdown renderers are installed by default.Run the following basic commands to compile Hexo
hexo clean
to clear the static files and cachehexo g
to generate static web files locallyhexo s
to start a local sever for preview
localhost:4000
by default. Now open http://localhost:4000
in your browser to see the result.hexo d
to deploy after generation finish (will talk this part in the following section)The Hexo community provides a lot of themes that you can choose to personalize your website. Navigate to the Hexo themes and select one to make your website attractive and professional.
Personally, I like Fluid, an elegant Material-Design theme, particularly for writing posts. If you prefer the other themes, the configuration method should be similar.
_config.fluid.yml
file in root dict is created for custom._config.yml
in root dict via replacing the theme config with your new theme name.Run the command hexo s
again and open the http://localhost:4000
in your browser to see the result using the Fluid theme.
For more configuration, please refer to Hexo Fluid Docs.
GitHub Pages is a static site hosting service that takes HTML, CSS, and JavaScript files straight from a repository on GitHub, optionally runs the files through a build process, and publishes a website.
To publish a user site, we can follow the getting started instructions to set up your site using GitHub Pages.
We should create a repository on GitHub.
+
, then click New repository
<username>.github.io
as the repository name. For example, if your username is octocat, the repository name should be octocat.github.io
. This link will end up being the base URL of your website.
Public
or Private
).Initialize this repository with a README
.Create repository
.You can generate a new SSH key on your local machine. After you generate the key, you can add the public key to your account on GitHub.com to enable authentication for Git operations over SSH.
<your_email>
with your GitHub email address.
You can add the generated SSH key and use it for authentication, or commit signing, or both.
Settings
.
Access
section of the sidebar, click SSH and GPG keys
.
New SSH key
or Add SSH key
Authentication Key
or Signing Key
.Add SSH key
.
ssh -T git@github.com
_config.yml
in root dictAs we have adopted the Fluid
theme in the _config.yml
file, we scroll down to the bottom of this file and update it with your depolyment target information.
At the root dict, right-click the mouse and click Open Git Bash Here
and then run the following basic commands
hexo clean
to clear the static files and cachehexo g && hexo s
to generate static web files locally and then to start a local sever at http://localhost:4000/
for previewhexo d
to deploy once you can make sure that all the info at http://localhost:4000/
are correct
INFO Deploy done: git
ERROR Deployer not found: git
, run the command npm install hexo-deployer-git --save
and regenerate and redepoly your materials via
https://github.com/<username>/<username>.github.io
, and then the Settings
at upper part of your web brower.Code and automation
section of the sidebar, click Pages
.
Build and deployment/Source
section, you should choose Deploy from a branch
main/(root)
at the Branch
section and save
itAt the root dict of Hexo project (<my-website>
), right-click the mouse and click Open Git Bash Here
hexo new "NEW hello world"
and it will create a new file (NEW-hello-world.md
) in <PATH>/source/_posts/>
with some default front-matter.After deployment, visit https://<username>.github.io
to see your live site.
Using GitHub Pages to build a personal website and distinguish yourself with a recognizable identity and external brand in your communities of interest is a worthwhile endeavor if youβre willing to spend some extra time setting things up. Hexo and Github Page become such a great tool for you. This pairing is a convenient, performant and free blogging platform. With its simplicity and its community, itβs easy to set up, allowing you to just focus on what matters: Your sharing. I hope you find this post useful.