Set an existing section as the homepage

If I have a section (“/channels”), how do I make it so that it displays as the homepage of my site?

Not on the homepage (potentially alongside other content), but as the homepage…

In other words, how do I set my homepage to “/channels”?

When someone accesses my site’s homepage, I want them to see a list of channels. If they were to go to “/channels”, I expect they’d get redirected back to the homepage, where they can see the canonical list of channels (to avoid SEO penalising me for duplicate content).

In case it affects the way to achieve this, note that I don’t use markdown to create pages on my site, I use Content adapters.

My site’s code can be viewed here: GitHub - NormPlum/FTW-Website · GitHub

If I get it right, you want to swap the pages. guess aliasing around here won’t work.

I could think of generate the full list at /channels and the list of pages FTW-channels to the root.

move your layouts/home.html to layouts/channel/section.html
and create a new layouts/home.html based on layouts/section.html adjusting the range

new layouts/home.html

{{ define "main" }}
  <h1>{{ .Title }}</h1>
  <h4>Section</h4>
  {{ .Content }}
  {{ range where site.RegularPages "Section" "channels"}}
    <section>
      <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
      {{ .Summary }}
    </section>
  {{ end }}
{{ end }}

you need to adjust your menu entries links and names “All channels” links to “/channels”, “FTW channels” links to “/”

Hint: exclude the about page from the RegularPages

Thank you! While I don’t actually want to swap the two pages per se, your code helped me to realise that I simply needed to edit the home.html template to be similar to the section.html template in the channels directory. I just needed to change {{ range .Pages }} to {{ range where site.RegularPages "Section" "channels" }} (as per your code).

1 Like

A slightly faster variant of the above is:

{{ $channels := site.GetPage "/channels" }}
{{ range $channels.RegularPagesRecursive }}
{{ end }}
3 Likes

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