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. 2 is the day, 2006 is the year. 02-01-2006 is the reference time in Go Language. So, the output for this article will be: 22 Ağustos, 2020 since we just mapped 08: Ağustos.

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


If you are curious, {{ .Site.Data.foo }} returns a map and index function returns the resulting value (“Ağustos”) for a given key (“8”). If you know about programming languages, a map is basically a dictionary and index function helps you get the corresponding value for a key.

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 7dfab23.
hugo
#data.yml #hugo #static-site
Next episode:
Data Files in Hugo
published on 29.08.2020
edited on 17.01.2022

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. […] {{ range .Site.RegularPages }} {{ .Title }} {{ end }} Also, notice inside range the scope is different. .Title refers to the page in current iteration. If …

published on 10.07.2022

Previously, I’ve published a blog post about deploying static content on heroku with basic authentication. You can find the link here. In that post, we hosted the source code on GitLab and configured a CI/CD pipeline to render the static content a.k.a html files and push these files to Heroku. …

published on 28.05.2022

Each git commit has a field called Author which consists ‘user.name’ and ‘user.email’. We usually set these variables once, after installing git, with git config --global so that each repo gets the variables from the global definition. We can also set them locally for a …

published on 25.05.2022

In this post, I’ll first walk through hosting static content with basic authentication. Then, we’ll look into deploying to Heroku using GitLab Pipelines, more specifically deploying a certain sub-directory within the project instead of pushing the whole project. Also, I’ll share …

published on 17.04.2022
edited on 15.07.2022

Önceki bölümde, markdown formatını LaTeX formatına dönüştürmek için kullanılan Pandoc yazılımından bahsetmiştik. Şimdi konuyu bir adım daha ileri taşıyıp ve bookdown’a geçiyoruz. Bookdown; Rmarkdown kullanarak teknik dökümanlar, kitaplar yazabilmemizi sağlayan, Yihui Xie tarafından yazılmış …

published on 10.04.2022

I’ve been using WSL-2 on Windows for over a year. It’s very useful because some Python packages are just a headache to install on Windows. Also, docker. It’s just better on Linux. Yet, WSL-2 can also be problematic. I remember trying a dual-boot setup when things just went way too …

published on 03.03.2022

In this post, I’ll share how to install geopandas and some other gis related packages on Windows. If you are on Mac or Linux you can probably just pip install those without any issue. I usually had to do a google search every time I wanted to install these packages on Windows environment. Of …