published on 22.08.2020

I like to display “published date” and “last modified date” info for my posts. Date info comes from the date parameter and last modified info comes from the lastmod parameter, both defined in the front-matter.

date: "2020-08-22"
lastmod: "2020-08-22"

Get Date-Info Partial

To get date-info I’ve created a simple partial template. Which basically, checks if the “lastmod” and publish dates are the same then renders the dates. To compare two dates, we should format them using the same date format. “02.01.2006” is equal to “dd.mm.yyyy” in the Go language.

{{ $date := .Date.Format "02.01.2006" }}
{{ $lastmod := .Lastmod.Format "02.01.2006" }}

<span class="date-info italic">published on {{ $date }}</span>
{{ if ne $lastmod $date }}
    <span class="date-info italic"> <br> edited on {{ .Lastmod.Format "02.01.2006" }}</span>
{{ end }}

Get LastMod Using Git

There is a very cool feature in Hugo, that can get the “lastmod” info from git. You need to enable it in the config file: config.toml.

enableGitInfo = true

Still, if lastmod parameter exists in front-matter, Hugo will use the date from the from-matter, not from git. So, you can freely enable the feature and use the parameter whenever you want to manually enter another date.

I realized that Hugo still using the lastmod info that is coming from git even if we set the lastmod parameter in the front-matter. The good thing is we can change this behavior by configuring front matter.

[frontmatter]
date = ["date", "publishDate", "lastmod"]
lastmod = ["lastmod", ":git", "date", "publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]

By default, ":git" comes before "lastmod". To override it, we need to add these lines to the config file.

You are reading the 9th of 19 episodes in Hugo.
Published on 22.08.2020 by Mert Bakır with commit db8d56a.
hugo
#hugo #static-site
Next episode:
Convert Dates Into Your Language in Hugo
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 …

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 10.07.2022

Previously, I’ve published a blog post about deploying static content on heroku with basic authentication. The main purpose was to get basic auth for a freely hosted static website. In that post, we hosted the source code on GitLab and configured a CI/CD pipeline to render the static content …

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 …