Would you consider using a Jekyll solution using Liquid templating instead of Ruby code? This is also a lot less code.
My solution lists pages at the exact same directory as the current page. Where the page that uses this includes
bit is index.md
{% assign pages = site.pages | sort: 'title' %}
<ul>
{% for item in pages %}
{% if item.dir == page.dir and item.path != page.path %}
<li> {{ item.name }} </li>
{% endif %}
{% endfor %}
</ul>
Then in a folder one level down, there is another index.md file which lists the page in it’s own directory.
I do a listing of pages as above as a bullet list and then I also have a menu of buttons for directories at the current directory. Which really means that for index.md
, if there is foo/index.md
and bar/index.md
then there are links to /foo/
and /bar/
If you prefer you could update my snippet to list pages at the current level and all nested levels below. By changing item.dir == page.dir
(which uses the current pages directory) you can use a starts with condition or contains
condition. Or you split the path string by /
so you can array of breadcrumbs and then you check the first few are equal.
Here is my snippet in context of a fork of minima. I used it for nested menus on a few sites.
Here is an example page Jekyll | Dev Cheatsheets