Stop from building Index.html for certain section

I have a problem where the “gallery” section of my content folder is only meant to display on the homepage of the site, thus the section’s index page and each page in the section serve no purpose, but are still being built.

Right now in layouts/section/gallery.html, I have this redirect: <meta http-equiv="refresh" content="0; URL='{{ .Site.BaseURL }}'">

And in config.toml:

[permalinks]
    gallery = "/"

But this creates some funky problems every other time hugo or hugo server is run. The site builds wrong and the home page is replaced by the latest “gallery” page that was built. Some strange redirect loop possibly.

Is there a way to stop certain pages from being built? Or a better way to do redirects in the theme?

I may have found a better way to do my redirects.

Created layouts/gallery/list.html and layouts/gallery/single.html with <meta http-equiv="refresh" content="0; URL='{{ .Site.BaseURL }}'"> in each.

Then got rid of the permalink section in the config file. Hugo seems to be building fine right now with no weird redirection mishaps, but still building all of those gallery pages my site doesn’t need.

If you don’t want these pages rendered it’s much simpler to move the gallery content files into the data folder.

This way you will be able to build the gallery in your index.html and not have its contents rendered as individual pages.

Look at the main branch of the Hugo Agency theme on Github for a way to use the data content. Particularly the portfolio section.

2 Likes

Thank you @alexandros , I think that’s the best solution for my problem.

How about in the _index.md of that section set outputs to an empty array in the front matter?

Interesting suggestion. And I tried it out for learning purposes. But I didn’t manage to exclude a section from rendering.

Just for reference’s sake in config.toml I already had:

[outputs]
home = [ “HTML”, “RSS”]
page = [ “HTML”]

And then in the frontmatter of a section’s _index.md as per your suggestion I tried setting outputs = "" to exclude it but it got rendered.