Generate the main home page in a subfolder instead of the base URL?

Hi again!

Following your advice, I think I got it working exactly the way I wanted.

What I did:

  1. In my customized theme (to avoid modifying the original one), I moved layouts/index.html to layouts/_default/hugo-profile-home.html, like you said.
  2. In layouts/index.html, I replaced its contents with those of layouts/_default/list.html. Then I replaced:
    {{ range .Paginator.Pages }}
    
    with
    {{ range (where .Site.RegularPages "Section" "blog") }}
    
    So that it only picks up pages inside the /blog folder.
  3. In /about/, I created an empty index.md file with the following parameter in its front matter:
    layout: hugo-profile-home
    
  4. I moved my previous /blog/_index.md file to the root of my site, so that it shows up above the list of blog posts just like before.
  5. To avoid my posts being shown at mysite.com/blog/name-of-post, I simply added this to the front matter of every blog post:
    url: "/name-of-post"
    
    I was already using the url parameter to customize the URL of each post, so it was just a matter of removing /blog/ from them.

And that’s it!

The only thing left was to modify the actual navbar links in hugo.yaml so that the “front page” sections now point to /about/section-name instead of /section-name, and do the opposite with the Blog link (now pointing to / instead of /blog).

I was honestly not expecting it to be this easy, especially considering I have a multi-language setup where the English version of the site (and all the blog posts) are at the root, whereas the Spanish version is under /es/. But I had already implemented proper handling and redirections when switching between languages, and because all paths are relative, everything worked automatically :slight_smile:

Thanks again for your fast and accurate help @davidsneighbour!

I was missing the bit of knowledge where you can make any page look like the default home page by just turning it into a layout in layouts/_default/, then referencing it by name in the front matter of any page. You nudged me in the right direction :slight_smile:

1 Like