Hosting my first blog for FREE using Hugo and GitHub Pages ๐
After conducting extensive research and considering various options, I decided to use Hugo as my Static Site Generator and Hugo themes for my blog
My plan is to host the static content on Github Pages under username.github.io and host the static server source code in another repository named username_blog_src. Finally, I will create a Github action to publish the content automatically.
Here are the steps I followed to start my blog:
- Install Hugo
- Create a first static Hugo website
- Choose a theme for my blog
- Create Github repositories for public content and source code
- Automate the process using GitHub Actions
- Publish my first blog
Installing Hugo
Hugo is a static HTML and CSS website generator, written in GO, and you can publish content using the Markdown language. Since I use Obsidian for my notes, I decided to publish my blog content using Markdown.
I use MacOs so I have decided to use brew to install hugo (https://gohugo.io/installation/macos/).
Run the following command in terminal:
|
|
Once Hugo is installed, you can use the command line by running hugo. Try running hugo –help to list all the options you can use.
Create a first static hugo website
I created two repositories in git:
- username.github.io - this repository will be used to host the public contect
- username_blog_src - this repository with be used to host the source code and it will be private repo
run the following in terminal
|
|
And voilร ! The new static site was created.
Choose a theme for my blog
Now we come to the hardest part: choosing the theme for the blog. As I plan to write a tech blog, I focused more on blog themes with a dark mode. I evaluated the following:
- PaperMod - https://github.com/adityatelange/hugo-PaperMod (GitHub stars: 4432)
- Coder - https://github.com/luizdepra/hugo-coder (GitHub stars: 2026)
- LoveIt - https://github.com/dillonzq/LoveIt (GitHub stars: 2279)
After evaluating these themes, I decided to choose LoveIt because it provides both a dark and light theme, is more colorful, and fits my personality and writing style. On top of all, I love it!
Winner: LoveIt - https://github.com/dillonzq/LoveIt (GitHub stars: 2279)
It was time to install the theme. I added the theme as a submodule in my source code by running:
|
|
Now you need to add the following to the config.toml file and replace baseURL, title, author.name, and author.email:
|
|
No if you want to have a sneak peak of how your website will look like run:
|
|
Open your browser and search for:
http://localhost:1313/
Create github repositories for public content and source code
Go to Github, login with your credentials and go to your repositories. Click new and create the following repositories:
- Repository 1:
- name: username.github.io (It must be the name of your github user)
- visibility: public
- Repository 2:
- name: username_blog_src
- visibility: private
When we created the site hugo creates a folder structure as following:
|
|
We need to publish the contents of public folder to our public repo: username.github.io and all others in our source repo (ignoring public folder).
|
|
Now we have to push the source code to the second repo:
|
|
Automate the workflow using github actions
-
Create a secret (PERSONAL_TOKEN) in Github actions with your personal access token (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
-
Create a new github action in git with the followign content
|
|
Publish my first blog
Run the following command :
|
|
Push it to the repo:
|
|
Conslusion
In conclusion, hosting your blog on Github Pages using Hugo and LoveIt theme is an easy and effective way to create a professional-looking website. The simplicity of Hugo’s static site generator, combined with the customization options of the LoveIt theme, make it easy to create a unique and visually appealing blog. Additionally, Github Pages’ free hosting service and built-in version control make it an accessible option for bloggers of all levels of experience. Overall, this combination provides a straightforward and powerful solution for creating a personal or professional blog on the web.