Hugo

Seeking Thoughts: What to do when a page doesn’t need to be built

Hi there,

I have what I consider to be a potentially strange use case, and I wanted to get some thoughts from the broader community on the various ways it could be tackled, as well as what might be the best-practices for building sites like mine in the future.

I’m a writer, and part of the site I’m building is planned to act as a portfolio of my writing. Some of that writing is going to be housed on-site, of course, but I think some of it is going to be housed off-site.

The problem: I want to be able to have all of the flexibility of normal front-matter, and use all of the same normal templating that’s built into the theme I’m writing (for which I’m using Ace, because it’s easier on my brain), while not having to have individual pages for items that are only going to be outbound links anyway. Where it would normally link to a page that would contain the content, it would simply link off-site, but the list pages would maintain all of the same ability to display anything that I would have otherwise been able to put in the front-matter of a normal page.

As Hugo is right now, it doesn’t give you a super easy way to do this that gives you the option to not actually build a page. You can create individual markdown files with no content, and set up the front matter that way, but no matter what you do in terms of template hacking and custom front matter to make the site do what you want, it will still build actual pages for each of those files and link them in your sitemap, for instance. This isn’t ideal.

One thing I could do instead is set up some custom JSON with the data for the off-site links. That way, I can pull that data, read in the site pages, merge it all in together at compile time, and draw my views that way. It’s a more elegant solution in terms of not building pages. This also requires a ton of extra work on my part, maintaining a bunch of extra code, and splitting my content across two separate locations and two separate formats. It’s also far, far from ideal.

What I would really like to see is a way that I can simply declare that a page doesn’t need to be rendered, and a property that specifies the actual link that any link to that page should point to instead, specifically added to Hugo. Honestly, I think this front matter property is likely one in the same — specify it, and it automatically doesn’t build the page, and any links to that page automatically go to the URL. Additionally, there’d be a variable that templates could use to determine whether a particular page was set up this way, so they could add target="_blank" rel="noopener noreferrer" or whatnot more easily to those links.

I opened an issue about this a few months ago, but it never saw much attention, so I wanted to post this here to see if I could get some more people’s thoughts on the matter. I think this could be a great addition to Hugo and it would certainly make it much easier to make websites that relied on this sort of functionality! Thanks for reading!

Please have a look at Headless Bundles:

This is the easiest and fastest way to render outbound links in list pages.

No need for data files for this simple functionality.

1 Like

def take a look at Page Bundles as @onedrawingperday suggested.

All of this ill probably have to do with your editorial workflow. I had a situation where I wanted to, in a list page, list out the titles of pages that were still a draft with then intention that as they were ready to be published that the Hugo would not only build the pages but link to them. In this case, I also wanted to control the directory structure in a way that (i believe) a headless page bundle would not allow.

Below is the solution that I can up with:

This is interesting! I don’t think this was an option when I was first looking into this at the beginning of the year, so it’s good to know that it is now. I’ll play around with the feature and see if I can get something hooked up using headless bundles. Thanks!