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: help.domain.com to achieve this, but, we are hosting our content in the following way:
Index (help.domain.com)
|
| - "Geting Started"
| - Getting Started Page 1.md
| - Getting Started Page 2.md
| - "Product Feature 1"
| - How to do XYZ.md
| - What if ABC happens.md
| - "Product Feature 2"
| - Example page 3.md
| - 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?
To give the concept of directory vs page, you iterate through all site.pages and if it is index.md 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.
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
site['product-feature']
...
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 tools.md 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.
<ul>
{% for tool in site.tools %}
<li>
<h2>
<a href="{{ tool.url | relative_url }}">
{{ tool.title }}
</a>
</h2>
<p>
<i>{{ tool.description }}</i>
</p>
<p>{{ tool.excerpt }}</p>
</li>
{% endfor %}
</ul>
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.