Create your blog With Hugo

How to create your blog with Hugo
Leitmotiv: Focus on writing blog articles (Avoid spending too much time for the perfect design or tool for your website)
Why Static Site Generator (Hugo)
Static Site Generator are tool like: Jekyll, Hugo, Hexo, Zola.
Key points:
- Generate a static website (html/javascript) based on markdown files
- Support templating tool with complex function
- No Maintenance
- Very low attack Risk (instead of wordpress tool for example)
- No complex requirements, only a web server like apache or nginx (i.e.: no dabatabase, no php)
- Low resources required
- Easy to switch from one theme to another
Hosting
You can host your blog for free on:
- Github Page (with Github action)
- Gitlab Page (with gitlab-ci )
It’s also possible to define a custom domain name if you have your own domain.
You can of course choose other paid solution:
- AWS
- GCP
- Self-hosted
- …
Install Hugo
extended version (with WebP images encoding and Transpile Sass to CSS)Hugo documentation offers a lots of features, sometimes it’s confusing but the quickstart is really good.
Hugo is written in GO so you can use directly release from github or use your package manager
Create your blog
To create your blog stucture, you just need:
|
|
This command will creates:
- config.toml: the config file for your blog site
- content: the directory which contains your articles in markdown format
- static: the directory which contains static content (favicon, avatar, …)
- themes: the directory which contains your theme
For further detail, see Directory Structure
Choose your theme
You can find a lots of theme for hugo in the official site
Choose one and put it in the theme directory.
I choose loveit theme for its features:
- Multi language
- responsive
- Customizable
- Very active
- Beautiful ( <- totally subjective)
To use this theme, execute this:
|
|
Write your first article
Create your article’s file
|
|
Each post contains :
- metadata in order to define title, author, tags and state (publish or not) in the headers
- your article content
For example, use your favorite editor and add this content in index.en.md:
|
|
Start the blog in testing mode
Launch Hugo server to see the result:
|
|
You can reach you blog at: http://localhost:1313/.
Each time you modify your article, the website is reload
Customize your theme
Add options from loveit theme inside your config.toml
|
|
Modify the config.toml in order to customize your blog:
- Website url (
baseURL) - Website title (
titleandparams.titleandparams.header.title.nameandparams.app.title) - Avatar picture (
params.home.profile.avatarURL) - Text below the avatar (
params.home.profile.subtitle) - Website description (
params.description) - …
You can also add this block in config.toml to add highlight and search:
|
|
Tips and Tricks
MultiLingual
For multilanguage support, you need:
- define the language in config.toml
|
|
- Create articles with the language code:
- index.en.md for english article
- index.fr.md for french article
Automatically hugo will detect articles, for example If i create 3 articles in english and french and one article in english only. The result will be:
- 4 articles if the language selected is english
- 3 articles if the language selected is french
Schedule Article
To schedule article, you need to define a publishDate in the future in the front matter:
|
|
And in this case, when you generate your site with hugo, if the date is anterior to publishDate the article is not published
Self sufficient (GDPR …)
To avoid cdn usage, you can download files used by this theme from cdn with this script):
|
|
All dependencies are stored in static/cdn/ and your website is autonomous.
You need to modify the value of libFiles by your website (https://www.thonis.fr/cdn/) in assets/data/cdn/jsdelivr.yml :
|
|
Analytics
Regarding the previous point, I disable any analytics and i use goaccess.
This tool scan your webserver log and generate a report (html or cli), so the most simple usage is:
|
|
In my case, i want to filter on a specific domain, add geoIP and also to use compressed log so i use:
|
|