Have a Home page but not where the home page should be

Hi all,

I thought I was so close to launching my site with Hugo but I’ve butted up against what I hope is easily solve-able.

I have my content for my site ready. At the root of my content folder I have my index.md. Currently when I deploy locally it works fine but at the next level down from the home page. I would like to have what is in this index.md to appear on the home page.

Having read this article I found that I was missing the index.html in Layout. So I created this file by copying and pasting the example in the Theme I’m using -Hugo-Kiera

The code within the index.html file that I copied is:

{{ define “main” }}

    {{ $pages := where site.RegularPages "Type" "posts" }} {{ $paginator := .Paginate $pages }} {{ range $index, $page := $paginator.Pages }}
    <li {{if eq $index 0}}class="first" {{end}}>
      <h1><a href="{{ $page.Permalink }}" title="{{ $page.Title }}">{{ .Title }}</a></h1>
      {{ partial "aside" . }}
      {{ partial "featured_image" .}}
      <p>{{ .Summary }}</p>
      {{ if .Truncated }}
      <a href="{{ .RelPermalink }}">{{ T "readMore" }}</a>
      {{ end }}
    </li>
    {{ end }}
    

{{ template “_internal/pagination.html” . }}

{{ end }}

But when I deploy this locally I get nothing for the main content of the home page.

Is the .html script above wrong?

Should I be using the example in this article?

Hope someone can help

index.md ==> Creates a leaf Page Bundle, that is ruled by the single page template usually under /layouts/_default/single.html

_index.md ==> Is an optional file meant to be used for metadata and custom content on list pages also known as branch Page Bundles, that are ruled by the list page template typically under /layouts/_default/list.html and in the case of the homepage the relevant template is /layouts/index.html

It appears that your homepage is missing its content due to using an index.md instead of _index.md

If the above does not fix the issue, then please share a repo with your project, to have a further look.

Thanks @alexandros. Based on you response here are the steps I’ve taken.

  1. Renamed index.md to _index.md
  2. Moved the index.html from /layouts/_default/ to /layouts/index.html

Still not having much luck though. My repo is https://github.com/TeldridgeLDN/servicexdesignv2

I think you’re missing {{ .Content }} in your index.html layout.

In line 5 of /layouts/index.html you are fetching the content files of Section called /posts/ however under /content/ there is no such Section hence the homepage list renders empty.

To fix

Either rename posts to post (the Section that is present under /content/

OR

Create a portable filter with mainSections.

Furthermore make sure to either un-draft the content files or run hugo server -D to build drafts for the homepage to be populated.

Thank you @IanMadd and @alexandros. Your suggestions have done the trick. Once again thanks for helping me out

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