Hugo from zero to hero
This is the meta-post. The post about how to build your own blog. I will use Hugo and a Linux machine.
Prerequisites
We need:
- Git
- Hugo
Install git
Verify if git is installed.
git --versionIf the command is not found, install it.
I am using Debian, so I’ll run:
apt-get install git
add-apt-repository ppa:git-core/ppa
apt update; apt install gitInstall Hugo
Verify if Hugo is installed. I am using v0.164.
hugo versionIf the command is not found, install it.
I am using Debian, so I’ll download this file and run:
sudo dpkg -i ~/Downloads/hugo_0.164.0_linux-amd64.debCreate a GitHub repository
This post is not just about creating a local blog, but also hosting it and having it published for everyone to see. For that, we will be using GitHub Pages.
If you don’t already have a GitHub account, create it.
Create a new repository and name it like this: <your_username>.github.io. This specific naming will tell GitHub that this repository will be deployed and published.
You can add your own description. I didn’t add a README and I chose GNU’s license. The repo needs to be public.
Hit create, now you have your new repository for your blog. This is mine.
Now you need to get your repository URL, click on Codeand copy the Clone URL, which should look like https://github.com/<your_username>/<your_username>.github.io.git.
Open a terminal in your PC (hopefully you are using Linux) and create a directory where the repository will be cloned.
git clone <YOUR_CLONE_URL>Now change your directory to the repository
cd <your_username>.github.io`Hugo won’t let you create a project in a directory that is not empty, so we will create a new project in a subdirectory and then move it back
hugo new project test
cp -r test .
rm -rf testWe can add a theme now, but we will leave it for later.
You can create a new page with
hugo new content <PATH>/<FILENAME>.mdBy default all new content gets created as a draft, so don’t forget to change that.
Or copy the content from this repo to get started faster.
Now run the server and click on the URL from the command output
hugo serverWe will need the deployment script for the GitHub Action. [1]
Create a workflow file
mkdir .github/workflows
editor .github/workflows/hugo.yamlAnd copy the content from here.
Next, add the following snippet to the hugo.toml file in the site root directory
You can customise now the content, or leave as it is for now, and then can commit and push the changes to your repository
git add .
git commit -m "My first personal blog"
git pushGitHub will run the workflow and publish the page