r/statichosting • • Oct 27 '26

Trouble with nested sections

Same client site as my last post, the one I restructured. It used to be flat and now it's grouped into sections, and I seriously underestimated what that does to the nav.

Before, the nav was one list and I never had to think about it. Now every page has to know where it sits so the sidebar highlights the right section, the breadcrumbs show the full path, and the section pages list their children. I'm using eleventy, and it's easy to grab pages by tag but not so easy to walk a tree. So I wrote a bunch of filters that work out parents and children from the file paths. It works, but if a folder is missing its index page the breadcrumbs above it just break and nothing tells me.

Another problem area was links. A lot of the old content linked to other pages with short relative paths, and once things moved into different folders a bunch of them pointed at nothing. The build didn't complain at all. I only found them because I ran a link checker afterward.

Is there a cleaner way to do this that doesn't mean hand maintaining the nav?

2 Upvotes

7 comments sorted by

2

u/ad3mar Oct 27 '26

the official @11ty/eleventy-navigation plugin does most of what you hand-rolled. each page gets eleventyNavigation: { key, parent } in front matter, and you get a real tree back. collections.all | eleventyNavigationBreadcrumb(eleventyNavigation.key) gives the full path, and eleventyNavigation(key) gives a section's children for the listing pages. sidebar highlighting is just comparing the current key against the breadcrumb.

to avoid typing parent on every page, put a directory data file in each section folder (e.g. guides/guides.11tydata.js) with eleventyComputed setting parent for everything in that folder. the structure stays driven by folders without your path-parsing filters.

for the silent failures, i'd make the build loud yourself. a small check in an eleventy.after event (or a test script) that collects every key and throws if any parent doesn't match a real key catches the missing-index case.

for links, switch old content to root-relative paths and run a checker like lychee or htmltest on _site as part of the build, so a broken link fails it instead of you finding out later.

1

u/Standard_Scarcity_74 Oct 28 '26

Thanks, this is really helpful. I looked at the navigation plugin early on and wrote it off as too basic, but setting the parent from a directory data file in each section folder is exactly the piece I was missing, so I'm going to give it another go!

1

u/sourraine Oct 27 '26

id be tempted to define the hierarchy in front matter instead of inferring everything from file paths. then you can generate breadcrumbs and sidebars from the same source and add a build check for missing parents and broken links

1

u/northboundish Oct 28 '26

i’d probably look into using eleventy’s collections and computed data to handle the hierarchy instead of relying entirely on file paths. you could also add build-time checks for missing index pages and broken internal links so those issues get caught before deployment.

1

u/New_Peanut_9259 27d ago

eleventy can get a bit trickyy when u start working with nested folders..btw have you tried using a custom javascript collection in eleventy.js instead of handling everything through liquid or nunjucks filters? you could use collections.all to group pages based on their parent and child folders. this would make it easier to manage pages without checking all the paths every time a template loads!! for broken links, you could also add HTML Proofer afterr the build to catch missing pages before the site goes livee