Create a sidebar ToC/Title + Sub Menu structure

I am using the minimal-mistakes theme (it has not been modified that much, if at all). I have posted a question in their discussion form already - but, also wanted to post here for some potential other ideas or view points on how to achieve this. This would be in the sidebar as described in the topic, but, ultimately,

We will be using a sub-domain: to achieve this, but, we are hosting our content in the following way:

Index (
|  - "Geting Started"
          |   - Getting Started Page
          |   - Getting Started Page
|   - "Product Feature 1"
          |   - How to do
          |   - What if ABC
|   - "Product Feature 2" 
          |   - Example page
   |   - etc
|  - Some other subfolder

What I am trying to do is extract the folder/directory names to be the titles, and page names to be the sub-title, to create the Sidebar menu automatically.

In any case, the Getting Started should be first, and then I can append/add the other items to the bottom which I know how to use that liquid function, but, what I can’t figure out is a good way to automatically retrieve the folder/directory name.

Is there an ideal way to do this? Is this better suited as a collection, rather than a page and several sub-pages/content?

Could anyone lend me some thoughts.


I can’t speak to using the specific theme. I don’t know if it supports a dynamic sidebar or you’d have to hardcode it

But generally.

If you don’t want to use a generator plugin, I’d recommend storing the directory names as pages. With the title set on the .md file


getting-started/ (`title: Getting started`) (`title: Example page 1`)

That is without a collections.

To give the concept of directory vs page, you iterate through all site.pages and if it is for name in path then it’s a directory.
Of course if you sort by paths alphabetically, all pages under one directory go together. Or you can use group by in Jekyll.

If the theme doesn’t support this you have to write this yourself for navbar.

Just remember Jekyll doesn’t know an is a directory. It is your logic.

So you can’t just get everything under say getting-started. You have to filter pages based on the same item.dir value.

If you want to use collections, then you can get everything under a directory. This could suit you better.

Your index page then needs to exist outside the collection directory and not called index.

Sample structure. Again, Jekyll doesn’t know the friendly name of a collection so use frontmatter for that.

_getting-started/ # collection (`title: Example page 1`)
_product-feature/ # collection

If you use config as:

permalink: pretty

Then your page URLs will appear as dirs.

E.g. Disk path and browser path: => /getting-started/
_getting-started/ => /getting-started/page-1/

Note that /getting-started/ points to /getting-started/index.html file.

But now say you have 10 collections and you don’t want to hardcode getting each one as

site['getting-started'] # like site.getting-started but handles hyphen 

Then you can use the site.collections object.

I have a demo here. I iterate through all collections without knowing the name beforehand and then list every page in the collection.

This appears on the body of my homepage as a menu like table of contents.

But this could easily be refactored as a sidebar.

For bonus points…

The top level of my tools collection is and I list all items in the one collection like so. This could be moved to a layout to avoid repeating code on every collection root.

title: Tools

This page showcases how to list items in a specific collection.

    {% for tool in %}
                <a href="{{ tool.url | relative_url }}">
                    {{ tool.title }}

                <i>{{ tool.description }}</i>
            <p>{{ tool.excerpt }}</p>
    {% endfor %}

All using the Minima theme by the way. But only using the theme for appearance. My logic to handle the TOC and the list of items within the collection is all my own code and nothing magical about the theme which means you can add that code to your site if you can’t find a builtin way for minimal mistakes from the docs.