published on 22.08.2020

We talked about rendering dates and the last modification date in the last post. Now, we’ll look into how can we convert month names into another language? I’ve had a similar experience last year with jekyll. The idea is the same, we need to map each month to their version of the preferred language and we need to store this information somewhere. We have data files for that.

1. Create a data file. /data/aylar.yaml

1: "Ocak"
2: "Şubat"
3: "Mart"
4: "Nisan"
5: "Mayıs"
6: "Haziran"
7: "Temmuz"
8: "Ağustos"
9: "Eylül"
10: "Ekim"
11: "Kasım"
12: "Aralık"

Now, you can access that data by calling {{ .Site.Data.aylar }}.

2. Format date using your data file.

{{ .Date.Format "02" }} {{ index .Site.Data.aylar (.Date.Format "1")}}, {{ .Date.Format "2006"}}

Remember, 1 means the month in date format. So, the output will be: 22 Ağustos, 2020

That’s it! You can do something similar for weekdays.

If you are curious, {{ }} returns a map and index function returns the resulting value (“Ağustos”) for a given key (“8”).

So, {{ .Site.Data.aylar }} will return map[1:Ocak 10:Ekim 11:Kasım 12:Aralık 2:Şubat 3:Mart 4:Nisan 5:Mayıs 6:Haziran 7:Temmuz 8:Ağustos 9:Eylül] and {{ index .Site.Data.aylar "8" }} return Ağustos.

You are reading the 10th of 19 episodes in Hugo.
Published on 22.08.2020 by Mert Bakır with commit 3a172e2.
#data.yml #hugo #web-dev
Next episode:
Data Files in Hugo
published on 29.08.2020

In Hugo and generally other static website generators, we are using data files to store data. These files can be in YAML, TOML, or JSON formats. You can always read more about data template in the original documentation. Yet, I want to give some examples from my blog. First of all, converting dates …

published on 30.08.2020

The question is clear. We need to pass variables or arguments in Hugo’s partials. We usually use only the dot when calling partials. {{ partial "foo.html" . }}. The dot means the current page’s context. All it’s variables like .Title, .Permalink, .Content and all others …

published on 23.08.2020

In Hugo, to loop through list of items we use Range function which comes from go language. range, iterates over a map, slice or array. […] 1 2 3 {{ range .Site.RegularPages }} {{ .Title }} {{ end }} Also, notice inside range the scope is different. .Title refers to the page in current …

published on 18.09.2020
edited on 13.02.2021

First of all, if you don’t know about data files, you may want to start reading from data files in hugo. This post is about a solution for a very particular problem. How can we use “group by” for the data from data files? Let me clarify with an example. I was creating a single page …

published on 24.01.2021
edited on 11.06.2021

Some time ago, I wanted to display image galleries on my Hugo website and searched for Hugo themes for photography and gallery. I can’t say I find much. Then, I met with a javascript library called nanogallery2 which is using another javascript library as an image viewer lightbox2. In this …

published on 23.01.2021
edited on 11.06.2021

Image processing may seem complicated at first but it’s actually easy and definitely worth implementing since it’ll help you decrease page load times. As you probably know, we don’t want to load raw images with huge sizes for small thumbnails or blog-posts. We want to load a small …