A quick localized archive page

Following a quick collection of scripts I use to localize my archive page. The page will sort entries by month with a list of links to entries… See samui-samui.de/archiv for the resulting output.

First I create a file in /data/months.toml containing the months name in my selected language:

months = [
  "",
  "Januar",
  "Februar",
  "März",
  "April",
  "Mai",
  "Juni",
  "Juli",
  "August",
  "September",
  "Oktober",
  "November",
  "Dezember"
]
  • the first item is empty, so we can use the normal indexing (1 = january, 2 = february,…) for the months
  • if your HTML defines UTF-8 as character encoding you can write special characters here (März), if not, you use entities (März). However… you want to use UTF-8.

then create a page template for your archive page.

{{ define "main" }}

<h1>Das Archiv</h1>
<p>W&auml;hrend ich auf diesen Seiten ein paar Umbauten vornehme, wird das Archiv leider nur eine liste mit Links zu den Artikeln sein. <p>
    <hr/>

    {{ range (where .Site.Pages "Section" "post").GroupByDate "January 2006"}}

        {{ range first 1 .Pages }}
            <h2>
                {{ index $.Site.Data.months.months .Date.Month }}
                {{ .Date.Format "2006" }}
            </h2>
        {{ end }}

        <ul class="list-inline">
            {{ range .Pages }}
            <li>
		        {{ .Date.Format "2" }}.
		        {{ index $.Site.Data.months.months .Date.Month }}
		        {{ .Date.Format "2006" }} - <a href="{{ .Permalink }}">{{ .Title }}</a></li>
            {{ end }}
    </ul>
    {{ end }}
{{ end }}
  • {{ range (where .Site.Pages "Section" "post").GroupByDate "January 2006"}} will sort by months (descending)
  • {{ range first 1 .Pages }} can be used to add a header per month
  • {{ index $.Site.Data.months.months .Date.Month }} is where we use the month names of the data file to echo localized month names.

I hope that’s useful for some. I am still working on getting a more verbose archive system going with pagination.