1

I have my Jekyll folder structure as

_includes
_layouts
_post
myFolder
   subMyFolder
   - readme.md
   subMyFolder2
   - README.md

   subMyFolder/subSub
   - readme.md
   - something.html
index.html

I wish to list all subMyFolders (just first level) without subSub folders and without files inside

My approach

{% for my_page in site.pages %}
  {% if my_page.url contains 'myFolder' %}
    {% if my_page.title %}
    <a class="page-link" href="{{ my_page.url | prepend: site.baseurl }}">{{ my_page.title }}</a> •
    {% endif %}
  {% endif %}
{% endfor %}

get the job partially don however when a subFolder has multiple items inside (page1.html, page2.html etc) its repeated on the list as well as my _config.yml has

include:
 - subFolder
exclude:
 - README.md

but still, I get subFolder/README.html despite the fact i've excluded it..

I need only the folders hierarchy of myFolders

Hus
  • 51
  • 4

2 Answers2

2

The best I could do with page.dir this would print the myFolder subfolders, assuming there is no other page with myFolder on the item.path

{% assign tools = site.pages | where_exp: "item" , "item.path contains 'myFolder'"| map: 'dir' | uniq %}
<ul>
  {% for tool in tools %}
    <li><a class="page-link" href="{{ tool | prepend: site.baseurl }}">{{ tool }}</a></li>
  {% endfor %}
</ul>

the problem this solution doesn't bring folder name if it's empty or unless it has a page :(

Hus
  • 51
  • 4
0

I think you should work with custom collections instead of subfolders in this manner but I'm not sure what your reasons are.

Are you excluding both README.md and readme.md? Which one is not working?

Keith Mifsud
  • 1,550
  • 1
  • 14
  • 24
  • I will play with it as collections, currently, README.md or readme.md not ignored inside /myFolder/subFolder/* however I just found I can call `{{ page.dir }}` Which bring me the directory of files, ex `{% for page in site.pages %} {{ page.dir }} {% endfor %}` I now need to remove duplicated value (folder name appearing twice) – Hus Jul 06 '18 at 15:14