The list of posts points to a directory instead of the post, why?

I am slowly progressing in Hugo, now building a blog (without a theme - it is a one-shot).

The problem I am having is that with my home page (layouts/index.html) …

{{ define "main" }}

<main>
    This is the home page, but better

    <ul>
        <!-- Ranges through content/posts/*.md -->
        {{ range .Pages }}
        <li>
            <a href="{{.Permalink}}">{{.Date.Format "2006-01-02"}} | {{.Title}}</a>
        </li>
        {{ end }}
    </ul>

</main>

{{ end }}

… I get the following output

this is the header
before main aaa
This is the home page, but better
  - 2022-05-01 | Posts
after main
This is the footer

2022-05-01 | Posts i supposed to be the test page I created at content/posts/postone.md:

---
title: "Post one"
date: 2022-05-01T22:12:06+02:00
draft: false
---

## this is the title of the post

### This is the first paragraph

Some text here with a --> and with a [some text]({{< ref "postone.md" >}})

Some **text** with a link to {{< gist wazaa gistId >}}

a link vers [google](https://google.com)

But in the output it is a link to http://localhost:1313/posts/!

Interestingly enough, the date is correct so it was somehow processed, just the output is wrong (points to the posts directory instead of the actual post(s)).

Would anyone know where the mistake is?

Change range .Pages to range site.RegularPages.

Thank you. Would you be so kind and elaborate a bit on why .Pages is not correct? I copied/pasted from the official docs at Lists of Content in Hugo | Hugo

This might help you understand

I saw that page, but it is not that helpful for a beginner. For instance, for .Pages, it says

Collection of regular pages and only first-level section pages under the current list page.

This does not explain why I had a directory when using .pages, but site.RegularPages was OK.

Since there are no regular pages in the root of the content folder, .Pages shows the section titles/names instead. From my limited understanding, the homepage behaves different as a list page hence the need to use site.RegularPages. You can also define custom variables to sort the posts even further.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.