Exclude _index.md from list

While searching for my issue, I figured I’d ask here instead of creating a new thread.

For the list page:
{{ $paginator := .Paginate (where .Site.RegularPages "Section" "psychedelics") }}
{{ range $paginator.Pages }}
...

For the Related Article Partial:
{{ $related := .Site.RegularPages.Related . | first 16 }}
{{ with $related }}

I am using the above code in my templates, and in the content/psychedelics/_index.md with some front matter:

+++
title="Psychedelic Research"
description="Explore the best resources in the psychedelic world"
hidden="true"
banner = "/img/banners/dream/4.jpg"
+++

It seems that this _index.md is being included in my loops even though I am using .Site.RegularPages.

https://dev.psychedelicsdaily.com/psychedelics/salvia/what-is-salvia-divinorum/ - toward the bottom of the page on Also Related Articles section, and on https://dev.psychedelicsdaily.com/psychedelics/ list page

Here’s some code from the layouts/section/psychedelics.html list template:

{{ $paginator := .Paginate (where .Site.RegularPages "Section" "psychedelics") }}
{{ range $paginator.Pages }}
                        <section class="post shadow box bg4">
                            <div class="row">
                                <div class="col-md-4">
                                  <div class="image shadow">
                                      <a href="{{ .Permalink }}">
                                          {{ if .Params.banner }}
                                          <img src="/img/placeholder.png" data-src="{{.Site.BaseURL}}{{ .Params.banner }}" class="img-responsive" alt="">
                                          {{ else }}
                                          <img src="/img/placeholder.png" class="img-responsive" alt="">
                                          {{ end }}
                                      </a>
                                  </div>
                                </div>

                                <div class="col-md-8 post-meta">
                                    <h2><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
                                    <p>{{.Description}}</p>
                                    <div class="clearfix">
                                        <p class="author-category">
                                          <!--{{ if isset .Params "author" }}
                                          {{$author := index .Site.Params.authors (.Params.author) }}
                                          <a class="" href="{{$baseurl}}authors/{{ .Params.authors | urlize }}/"><i class="fa fa-user" aria-hidden="true"></i>{{$author.display_name}}</a>
                                          {{ end }}-->

                                        {{ range $index, $tag := .Params.tags }}
                                        <a class="" href="{{$baseurl}}tags/{{ $tag | urlize }}/"><i class="fa fa-hashtag" aria-hidden="true"></i>{{ $tag }}</a>,
                                        {{ end }}

                                          <!--{{ if isset .Params "categories" }}
                                          {{ if gt (len .Params.categories) 0 }}
                                          <a href="{{ $.Site.BaseURL }}categories/{{ index .Params.categories 0 | urlize | lower }}"><i class="fa fa-folder" aria-hidden="true"></i>{{ index .Params.categories 0 }}</a>
                                          {{ end }}
                                          {{ end }}-->
                                          <br>
                                          <a href="{{ .Permalink }}"><i class="fa fa-clock-o"></i> {{ .Date.Format .Site.Params.date_format }}</a>
                                        </p>
                                    </div>
                                    <!--<p class="read-more"><a href="{{ .Permalink }}" class="btn btn-template-main shadow"><i class="fa fa-list-alt" aria-hidden="true"></i> {{ i18n "continueReading" }}</a>
                                    </p>-->
                                </div>
                                <!--<div class="article-share" style="text-align: left;">

                                    {{ partial "share.html" .}}

                                </div>-->
                            </div>
                        </section>
{{ end }}

Partial for Related.html

<div class="related">
    {{ $related := .Site.RegularPages.Related . | first 16 }}
    {{ with $related }}

    <div><h2>See Also Related Articles</h2></div>
    <div class="row">
        {{ range . }}
        {{ if ne .Section "" }}
        <div class="col-md-3 col-sm-6">
            <div class="box-image-text">
                <div class="top">
                    <div class="image shadow" style="overflow:hidden">
                        <a href="{{ .RelPermalink }}">
                        {{ if isset .Params "banner" }}
                        <img src="{{ .Site.BaseURL}}img/placeholder.png" data-src="{{ .Site.BaseURL}}{{ .Params.banner }}" class="img-responsive shadow" alt="{{.Title}}" width="255" height="192" title="{{.Title}}">
                        {{ else }}
                            <img src="{{ .Site.BaseURL}}img/placeholder.png" class="img-responsive" alt="{{.Title}}" width="255" height="192" title="{{.Title}}">
                        {{ end }}
                        </a>
                    </div>
                    <a href="{{ .RelPermalink }}"><h4>{{ .Title }}<h4></a>
                </div>
            </div>
        </div>
        {{ end }}
        {{ end }}
    </div>
    {{ end }}
</div>

They both render very wrongly. They both have an href = https://dev.psychedelicsdaily.com/psychedelics/

I am using Hugo vesion 0.69 (latest) and a heavily modified Hugo Universal Theme

I can’t seem to exclude this. Any advice?

Here is the git repo: https://gitlab.com/hashborgir/psychedelicsdaily.com-hugo.git I’ve made it public.

The topic you were responding to is years old now and many things have changed in Hugo since. I’ve moved your question to its own thread.

It would be easier to help you with a repo we can clone.

Thank you.

Here is the repo: https://gitlab.com/hashborgir/psychedelicsdaily.com-hugo.git in the hugo-dev branch

I started Hugo when I barely understood it, so I ended up basically making all my changes in the /themes/ directory directly.

  1. You have an empty md file here
  2. Your Permalinks config includes this

Sometimes, point 1 gets resolved to Permalink /:sections/slug/ => /psychedelics/ because there is no slug, which collides with your /psychedelics/_index.md so that it “looks” like a single page (ie part of RegularPages) instead of a list page.

2 Likes

Thank you.

All because of an empty .md file with no slug.

I believe removing that empty .md file did the trick. I don’t recall how that even got there.

Is this the correct fix, unless there is something I have misunderstood.

Either deleting the file if it is not needed, or defining a title or slug in the frontmatter if you do want the page to exist.

Yup. That’s what I figured. Thank you.

I’m not blameing ya… but git is!

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