+++
title = "Creating archive pages grouped by year in Hugo"
date = 2019-11-15T15:30:03+05:30
draft = false
tags = ["hugo", "blog", "golang"]
categories = ["tutorials"]
type = "post"
url = "blog/2019/11/15/archive-pages-group-by-year-hugo"
author = "Rohan Verma"
+++
I was on the hunt to find out how to organize my [blog](/blog_list) and
[project](/project) archive pages by year in Hugo. After being unable to find
any easy solutions I decided I would sit down and write the go template to
render these pages myself. The idea was simple, iterate over the list divided
by year into sub lists and render tables, but it turned out to be a bit tricky.
Here is the template, hope it is useful for someone who wants to have a similar
page.
```html
{{ define "title" -}}
Blog List | {{ .Site.Title }}
{{- end }}
{{ define "header" }}
{{ partial "masthead.html" . }}
{{ end }}
{{ define "main" }}
{{ .Title }}
{{ .Date.Format "2006" }}
{{end}}
{{ $prev = .Date.Format "2006"}}
{{end}}
{{end}}
{{.Date.Format "02 Jan"}}
{{.Title}}