How to use a single list.html layout for each content/posts/section/, listing just posts from that section?

There are a few things I want to accomplish:

  • Making my permalinks site.com/section/postname/ ( no “/posts/” anywhere)
  • Letting users visit site.com/section to list all the posts in content/posts/section/
  • Using a single template for each of those list pages.

I am trying many different things but everything I do either does nothing or breaks hugo server.

I have tried:

  • adding a layouts/posts/section.html
  • adding a layouts/posts/list.html
  • adding a layouts/defaults/section.html

I have uploaded a short video here showing hugo server breaking. I guess because I’ve added a blank _index.md:

REMOVED

Can someone please help me understand how to achieve my goals. I used to use hugo extensively but it’s been a year or two now. I switched to Gatsby and have now switched back…

@jascke

I removed the link to the NSFW video and locked your post.

Do not post a NSFW video again here, no matter the excuse.

Regarding the support question please do have a look at:

Also search the forum. This has been discussed many times. It is possible to remove posts/ from a section’s permalinks.

Also read up about:

Thanks.

Do not post a NSFW video again here, no matter the excuse.

Okay, understood. Sorry I did not know this was a rule. I just figured with adequate warning it would be fine. Can you please do me a favor and edit my OP to remove the first all-caps line. (“Note that… is NSFW:”). I intended to remove that (for privacy) after my issue was resolved.

I have read both of the docs you linked prior to posting but I am still having trouble.

When I use this in my config:

[permalinks]
  posts = "/:sections/:title/"

My URLs, which are generated using {{.Permalink}}, are still /post/abc/ (not /post/section/abc/ like I want). Even if i create /posts/section/_index.md and write the following into the file:

+++
title = "fdsf"
+++ 

# fsdf

fdsf

I also already have a /layouts/_defaults/section.html and yet I can’t access localhost:1313/section/ … I just get a 404 when I try. Even when there’s an _index.md in /content/posts/section/ . According to the lookup order doc this should solve that issue but it doesn’t seem to.

I guess really what would be most helpful would having an example site repo to reference which includes posts organized into subfolders and section list layouts for navigating those posts. I checked quite a few themes before posting my question but was unable to find any examples.

This is a technical support forum for a static site generator called Hugo.

People come here for the above reason.

They go elsewhere for the other stuff.


Hopefully someone else can pick up from here regarding the Support question as I have to go.

Thanks for the understanding.

1 Like

A ‘section’ in Hugo is one directory off from content.

content/posts/  <- section is "posts"
content/posts/section/ <- section is "posts"
content/posts/section/another-one/ <- section is "posts"
content/section/ <- section is "section"
content/section/posts/ <- section is "section"

I suggest creating a small project with a simple section, not sub-directories, and build up from there.

And for what it’s worth, because some folks don’t get explicit directions for life:

DO NOT POST PORN TO SUPPORT FORUMS.

3 Likes

I solved the problem by abandoning /posts/ and making each category into a section. Thank you both. fyi if it matters there wasn’t ever actually any nudity, just filenames…