How to directly show posts from `content/posts/` on home page?

Hello.

This is my Day 1 in Hugo and I’ve made some self-satisfactory progress by reading a lot of posts on these forums, documentation, GitHub and others’ blogs. However, now, I’ stuck at a point for which I don’t seem to be getting an answer.

Basically, for organization purposes, I’m willing to add all my posts in content/posts directory. However, on the home page, I’d like to directly display the posts list instead of displaying the link to posts directory first and then the actual post.

Here’s what I’ve done (the snippets have been truncated to show only the bare layout of the HTML so as to not create a mess in this post):

layouts/default/baseof.html:

<!DOCTYPE html>
<html lang = "en">
  <head>
    <!-- Styles and scripts -->
  </head>
  <body>
    {{ block "main" . }}
    {{ end }}
  </body>
</html>

layouts/index.html:

{{ define "main" }}
      {{ range where .Data.Pages "Section" "posts" }}
                <a href = "{{.RelPermalink}}">{{ .Title }}</a>
      {{ end }}
{{ end }}

So, as I said before, even after (probably) filtering out posts only from the section (contents/posts/) on the home page, I am still seeing the link to the directory and not to the post. What am I missing?

Just to be clear, I’m not using any pre-built theme, I’m experimenting myself.

One way to achieve that would be using something like: where .Site.RegularPages "Type" "in" .Site.Params.mainSections.

To understand why, see:

1 Like

The exact thing. Thanks for the docs link too. That has even more interesting info. I had looked on the functions page, but, couldn’t make out that where could help. Thanks a lot again.

1 Like

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