Hugo is one of the most popular open-source static site generators. With its amazing speed and flexibility, Hugo makes building websites fun again.
That's in the Hugo website and I guess it's true, since I find it very easy to use to publish this dumb blog when I have the time to.
Now, Hugo will generate the static site in your PC but how can you make it accessible from the Internet? Well… GitHub Pages is the savior.
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.
Aaah you see?! Hugo generates the static site and GitHub Pages host this site to make it public. So we need both.
So lets start.
Please note that the following instructions and commands are run from a Terminal.
Create the GitHub page host
In order to publish your blog, you will need to create a host and as we said, we will be using GitHub Pages for that.
- First create from GitHub a repository
<USERNAME>.github.io
to host your generated content. You can follow GitHub instructions here, it's very simple and clear to understand. - Make sure that under Settings of your
<USERNAME>.github.io
themain(or master)
branch and the/(root)
folder are selected as Source, to publish your GitHub Pages site. - Be aware that the repository creation will take around 20-30 minutes to be available online.
- Also intall git
sudo pacman -S git
(Need help for installing?)
Creating the blog with Hugo.
- Install Hugo. In Archlinux just
sudo pacman -S hugo
(see Hugo Install Instructions for other operating systems). Create a site/blog with
hugo new site "yourSite"
- This will create a folder name
yourSite
- This will create a folder name
- Enter to that folder
cd yourSite
- Add a theme. I am using Meme theme which was added with
git submodule add --depth 1t https://github.com/reuixiy/hugo-theme-meme.git themes/meme
There are a lot of themes you can choose from the Hugo theme page. Configuring the theme is not difficult —I will not detail it. Now add a new post with
hugo new posts/NewPost.org
. As you can see, I am using an org to write the post (see a brief explanation of what org mode is), but it can be done using the markdown syntax as well.- You will see a new file
NewPost.org
created undercontent/posts
folder. This file will include the content of your post/blog entry. The file will begin with something like this
--- title: "NewPost" date: 2021-01-03T19:37:05-06:00 draft: true ---
- You will see a new file
- Once you are done with editing and writing you can preview the results with
hugo server -D
this will create a local page (including Drafts, that's the reason of-D
) which you can access from your browser inhttp://localhost:1313/
You can close the server by pressingCrtl+c
. Configure your
config.toml
file located insideyourSite
folder. It might start with something like this:baseURL = "https://example.org/" languageCode = "en-us" title = "My New Hugo Site" theme = "ananke"
- Replace the
baseURL
URL with your<USERNAME.github.io
- Change the tittle and select your theme. We are using here
meme
theme. - This is pretty much all the config you need for now. I will not explain more since it depends on the theme you choose.
- Replace the
- Before proceeding run
rm -rf public
to completely remove the public directory (this does not need to be done on every update). - Change
draft: true
to false in your post and runhugo
to export theNewPost.org
as an html file. - Finally, bind your GitHub repository to your public directory where Hugo will store the pages to be published with
git submodule add -b main https://github.com/<USERNAME>/<USERNAME>.github.io.git public
(this does not need to be done on every update).
Update your git repository
You have already exported your blog entry. Now it's time to make it public in the internet.
- From inside your
public
folder (which is located insideyourSite
folder) rungit add .
to upload all the files to your<USERNAME>.github.io
repository. - Now commit the changes
git commit -m "My first blog"
- And finally make it public with
git push origin master
- That's it. You are done. You are able to access to your blog in
<USERNAME>.github.io
domain.
More information about Hugo can be found here and here.
You can uso Hugo with gitlab as a Host for your website. See gitlab info here.
If you found this content useful, please support me:
BTC: 1E2YjL6ysiPxRF4AEdXChpzpesRuyzgE1y