Posts with sub-pages

Please excuse me if this has been answered before, but I just haven’t been able to find an answer. It seems like a very simple question, but well, let’s see.

I’m trying to have a site where my posts can have sub-pages that can be linked to from the posts, but aren’t considered posts, themselves.

Based on my readings so far, and given my understanding of leaf bundles and branch bundles, it is not a straightforward matter to arrange things so that all these are valid URLs showing normal web content (ie none are listings):

  1. mysite/posts/my-first-post/
  2. mysite/posts/my-second-post/
  3. mysite/posts/my-second-post/some-details/

I want #1 and #2 to be classified as “posts”, and I want #3 to be a “post subpage” (preferably without explicit typing in matter, but I’ll accept that if it’s the best way). How is this done?

The first one is straightforward, of course. It is generated from content/posts/my-first-post. But then, how do I (preferably automatically) classify some-details as something other than a post? I want it to be processed, but I don’t want it showing up in the list of posts. After that’s working, I still need to know how to generate the output for the main my-second-post page and have it shown in listings of posts.

I’m really hoping that I’ve misunderstood something, or that this needn’t be solved by lots of trickery and overriding of implicit typing. But even if the solution does require jumping through hoops, your advice will be appreciated!!

By definition, list pages are _index.md. And it is not mandatory to have an _index.md file in a (local) directory.

The question of whether the sources are accurate:

mysite/posts/my-first-post.md
mysite/posts/my-second-post.md
mysite/posts/my-second-post/some-details.md

is not the same as:

mysite/posts/my-first-post/_index.md
mysite/posts/my-second-post.md
mysite/posts/my-second-post/some-details/index.md

is not the same as:

mysite/posts/my-first-post/_index.md
mysite/posts/my-second-post.md
mysite/posts/my-second-post/some-details/_index.md

mmh, I read that a few times and each time I get a different understanding of your target.

especially this

I want it to be processed, but I don’t want it showing up in the list of posts.` you don’t want my-first-post to show up in /posts listings?

Let me nevertheless give some hints to consider.

  • keep in mind, that a section (folder containing _index.md) is also a Page. The content of that pages depends on your templates.

    /layouts
    │
    ├───posts
    │       section.html   <-- this renders Posts (*all* folders with an _index.md)
    │       page.html      <-- this renders sub pages (all *not* containing an _index.md)
    

    If your section does not range over pages, you get no listing.
    dunno if you want to nest subpages within subpages or it’s just a two level stuff

  • you could also use front matter layout parameter to target a template.

    layout = 'post
    layout = 'subpage'
    

    and use named layouts regardless of page kind

    /layouts
    │
    ├───posts
    │       post.html      <-- this renders Posts
    │       subpage.html   <-- this renders sub pages
    
  • block pages from being listed can be achived using build options
    with this in your /content/posts/_index.md’s front matter. nothing in /postswill be listed in any page collection but renderd, so you can use GetPage or links to refer to pages

    [[cascade]]
     [cascade.build]
       list = 'never'
       render = 'always'
    

    as I said, I’m not sure if you need some listings somewhere. linking all manual seems glumbsy

  • cascade can also be used to propate params to child pages
    with this in your /content/posts/_index.md all toplevel entries (/posts/xxx.md and /posts/xxx/index.md) will get layout = 'post' all deeper get layout = 'subpage'

    [[cascade]]
      [cascade.params]
        layout = 'post'
      [cascade.target]
        path = '/posts/*'
    [[cascade]]
      [cascade.params]
        layout = 'subpage'
      [cascade.target]
        path = '/posts/*/**'
    
  • keep in mind, that if you do: posts/one.md and posts/one/subone.md both pages logically belong to the Posts section


I did not understand all details about your intent: pages(nested), classifiy(?), listing and accessing pages, but I hope that helps:

  • to get a feeling whats possible (and there is more)
  • detailing your target structure and usage.
Example content tree - (post-3 varaint I would not recommend)
ONTENT\POSTS
│   post-3.md
│   _index.md
│
├───post-1
│   │   sub-1-1.md
│   │   sub-1-2.md
│   │   _index.md
│   │
│   ├───sub-1-3
│   │       index.md
│   │
│   └───sub-1-4
│           sub-1-4-1.md
│           _index.md
│
├───post-2
│   │   _index.md
│   │
│   ├───sub-2-1
│   │       index.md
│   │
│   └───sub-2-2
│           index.md
│
└───post-3
    │   sub-3-2.md
    │
    └───sub-3-1
            index.md
1 Like

Thank you for your response! It has given me a few things to think about and try.

First off, I apologize for the ambiguity that made my question harder to understand. I should have said, “I want some-details [instead of “it”] to be processed, but I don’t want it showing up in the list of posts.” I hope it’s all clear and consistent now!

So experimenting with what I know, here how I set up a test:

hugo new content posts/post-1/index.md
hugo new content posts/post/2.md
hugo new content posts/post-3/index.md
hugo new content posts/post-3/subpage.md
hugo new content posts/post-4/_index.md
hugo new content posts/post-4/subpage-1.md
hugo new content posts/post-4/subpage-2/index.md

Incidentally, the command to make the post-3/subpage crashes Hugo for me, so that’s a sign that that’s not a good thing to be trying to do. Before crashing it does create the subpage.md file for me, but here are the contents:

---
title: "Content Placeholder"
build:
  render: never
  list: never
  publishResources: false
---

Here’s the file tree:

content
└── posts
    ├── post-1
    │   └── index.md
    ├── post
    │   └── 2.md
    ├── post-3
    │   ├── index.md
    │   └── subpage.md
    └── post-4
        ├── _index.md
        ├── subpage-1.md
        └── subpage-2
            └── index.md

Anyway, just from that, when I point my browser at the posts directory, I get a listing of “Post 1”, “2”, and “Post 3”. “Post 4” is missing!

The following 3 URLs work, as expected:

mysite/posts/post-1/
mysite/posts/post/2/
mysite/posts/post-3/

But this one does not

mysite/posts/post-3/subpage/

I tried repairing the contents of post-3/subpage.md to have frontmatter like post-1.md, but it still isn’t generated. Running hugo list all shows that Hugo isn’t seeing the subpage.md file. I guess, post-3 being a leaf bundle means it can’t have descendants even only in the URL sense. I’m OK abandoning that avenue.

As for this URL,

mysite/posts/post-4/

it is interesting that it works, and shows a listing containing subpage-1 and subpage-2, but neither post-4, subpage-1, nor subpage-2 were considered posts to the extent that they would be listed at the posts directory.

Thinking about it, post-4 is a branch bundle and a section, by virtue of having _index.md at its root. I don’t know if that’s what makes it not show up in the post listings, but that’s already a problem for me. Briefly, the organisation I described at the beginning was aiming to allow augmentation of normal posts with sub-pages, but now I can’t even have the normal posts.

So far I haven’t even dipped my toes into the idea of overriding layout in the frontmatter as you’ve suggested, because the listings are actually not broad enough. I need to get post-4 working as a branch bundle and a post. Any suggestions?

exactly - it’s a resource of the page (so no content, guess that’s why hugo new fails)

So maybe we just overcomplicated things here and I still don’t get what “I want some-details [instead of “it”] to be processed”

Let’s simplify things here:

to get childs of pages the way is using branch bundles

source and target structure
  • post with subpages as branch bundle

    CONTENT\POSTS
    │   _index.md
    └───post-4
        │   subpage-1.md
        │   _index.md
        └───subpage-2
                index.md
    
  • and will render to:

    PUBLIC\POSTS
    │   index.html
    └───post-4
        │   index.html
        ├───subpage-1
        │       index.html
        │
        └───subpage-2
                index.html
    

The rest is all about “How your target site should display” and what “works as wranch bundle and post” is for you (content on rendered pages).

  • On which page you want to list which pages?
    • Home Page
    • Menus
    • Main Sections
  • where should the subpages be listed?
    • just as main pages on ???
    • only on the parent page
  • what’s the some details?
  • whats "work as

depending on this you may use range, where, … with page sets to display.
Dependent on the above you mag need dedicated templates, or…


Here’s a bare site with some listings and a post-4 setup - nothing special in like custom layouts, build or cascade settings. maybe it helps us to track down your requirements.

git clone --single-branch -b topic-56364-SubPages --depth 1 https://github.com/irkode/hugo-forum.git
cd topic-56364-SubPages
hugo server
1 Like

I just mean I want the html corresponding to some-details to be generated and be browsable in the expected place. Please don’t be confused by this - this answer about some-details is in the context of my original question. All answers below are about the test I did where I gave you hugo new content commands, and in that context, the post-4/subpage-1.md and post4/subpage_2/index.md and their corresponding html files play the role of some-details in my original question. And they are being processed just fine in the test project I have. So my requirement of some-details being processed, is being met in the structure I made in my test. The problem with solving it that way is in the listings that result being incomplete.

That is exactly what I expect, and actually, what is being rendered for me matches that layout. The problem is the contents of public/posts/index.html (see below).

I suspect that if there are any problems with the three elements above, they will be solved when we solve this in the listing I’m talking about. The particular listing I’m talking about is the one at public/posts/index.html (at least with the themes I’ve tried, including ananke, from the QuickStart instructions). The way (at least some) public themes collect pages seems to be excluding post-4.

They don’t need to be listed anywhere, for me. There will be links to them from their parent “post” pages.

It’s just extra information that was sectioned off from the main post, with the goal of keeping the post more brief. Think of it like a sidebar in a magazine article.

Thank you very much for the git project you supplied. It does let us talk about this less ambiguously. What is rendered for public/posts/index.html from that project includes:

Content of content\posts\index.md
.Pages
    Post 4: content/posts/post-4/_index.md
.Sections
    Post 4: content/posts/post-4/_index.md

Your sections layout code is clearly picking up post-4 as a page. Without looking at any corresponding code in them, I’m speculating that there might be a convention in the public themes that section listings ignore any child pages that are also sub-sections.

When I tweak your project, put in the ananke theme, and rename your layouts directory so the theme layouts are used, public/posts/index.html doesn’t show post-4 in its listing.

I hope I’m misunderstanding something here and the problem is something other than a convention, because I don’t want to fight them if they are well established. But if that is the case, I’m wondering how else I would achieve the results I’m after. I guess I just wish there was a way of making a branch bundle without it being considered a sub-section.

I would not tell it like that, but themes for blogs often treat posts as one pagers, which might have effect you see. Some can be configured (check their docs), some not… some are easy to adjust, some not.

no way - but you can configure your site config and layouts to treat them as…

that all said:

  • leaf and branch bundles are what they are
  • you can always adjust how these are processed with config and layouts
  • a Theme usually couples Content organisation and Layouts
  • maybe a theme focusing on articles or docs may do, maybe you just found a blog theme that supports that maybe with a setting
  • adjusting a theme is a completely different discussion and will need “to look into code”

conclusion

I would consider this “discussion about bundles and pages” topic as answered.

If you got the insights you need, mark it as solved.

If you come up with a dedicated setup/config/implementation/theme and have a specific problem that you cannot solve I’m pretty sure we can assist.

In that case, please create a new topic and share what you have (see Requesting Help)


p.s. there’s an open issue for ananke that it does not use Hugo’s v0.146+ layout system. Maybe not the best to play with…

2 Likes

Thank you for all your input! It has helped immensely. You have answered my questions, and I will mark this as solved after I’ve had a look at the layout code in some themes. I’m pretty sure I will have some thoughts to share, but I want to know more before I say anything.

In the end, for the theme that I’m actually using (PaperMod), what was needed was that in my content/posts/post-4/_index.md, I included the following:

[[cascade]]
  [cascade.build]
    list = 'never'
    publishResources = false
[build]
  list = 'always'

The cascade section is configuring the build settings for the subpages to have list = ‘never’, because I don’t want the PaperMod automatic listing of section pages to happen after the contents of my post-4 page. But the cascade section actually affects the listing of post-4 in the posts page, which I don’t want. So I override the local build setting to ‘always’ after configuring cascade.

Note: there is still the problem of post-4 not showing up in the main page listings. I have not looked into that much, because in my case, I actually don’t want the posts showing up on the main page, and I have cleared out the mainSections array in my hugo.toml.

fyi:

  • [ wrong ]Roadster a Mainroad theme fork seems better maintained. If I got it right it is also updated to hugos 146+ layout system.

  • Ananke theme recently also got some updates for 146+

Correction! It is a Mainroad theme fork!

1 Like

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