I have converted my blog to Hugo, from Octopress. Transition went smootly and the only annoyance is that my archives page is showing a nonexisting “Posts” post at the top.
I have added theme/layout/archives/list.html which contains this:
{{ partial "head.html" . }}
<div class="content container">
<h1>Blog archives</h1>
{{ range (where .Site.Pages "Type" "post").GroupByDate "2006" }}
<section class="archive">
<h2>{{ .Key }}</h2>
<ul>
{{ range .Pages }}
<li><time>{{ .Date.Format "Jan 2" }}</time>
<br><a href="{{ .Permalink }}" class="permalink">{{ .Title }}</a>
{{ if isset .Params "categories" }}
<br><span class="post-tags">
<span class="prefix">categories:</span> {{ range .Params.categories }}
<a href="/categories/{{ . | urlize }}">{{ . }}</a> ·
{{ end }}
</span>
{{ end }}
{{ if isset .Params "tags" }}
<br><span class="post-tags">
<span class="prefix">tags:</span> {{ range .Params.tags }}
<a href="/tags/{{ . | urlize }}">{{ . }}</a> ·
{{ end }}
</span>
{{ end }}
</li>
{{ end }}
</ul>
</section>
{{ end }}
</div>
{{ partial "foot.html" . }}
I can’t figure out how to remove this “Posts” item.
Note that I have content/archives/_index.md (which is empty) - otherwise this page is never generated. Not sure is that correct way to create date-based list of posts, but nothing else seemed to work.
{{ range (where .Data.Pages "Type" "post").GroupByDate "2006" }}
throws no errors, but also no data appears on the page. Like the range.count is 0. It looks like it’s missing the context what .Data is supposed to be.
{{ with .Site.GetPage "section" "post" }} {{ range .Data.Pages.GroupByDate "2006-01" }} Archives Title and {{ .Key }} markup here {{ range .Pages }} The rest of your markup goes here {{ end }} {{ end }} {{ end }}
I’m a Hugo beginner. I’m asking this because I’m still learning.
I had the same problem with the dangling ‘post’ entry. I solved it by using range where.
{{ range where .Site.Pages "Section" "post" }}
{{ range (.Pages.GroupByDate "2006") }}
-year key
{{ range (.Pages.GroupByDate "1") }}
- month key
{{ range .Pages}}
{{ .Render "summary" }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
My question is: are there any reasons not to use this construct? I like it more because I do not have to use .Data which makes it a bit easier for me to comprehend whilst reading.