Show pages under one folder in Jekyll?
Asked Answered
M

1

7

I think the native way of managing pages of Jekyll, i.e. by creating .md file / folders under the root folder, is a bit messy.

Thus I want to put, every page I want to show, into the folder called "pages". Additionally, I'd like these pages to have a cascaded structure: say if my folder has the structure:

pages
 |-> parent1
      |-> index.html
      |-> son1.html
      |-> son2.html
 |-> parent2
      |-> index.html

Then in the pages-listing page, it should be something like this:

page listing
 * parent1
   * son1
   * son2
 * parent2

And additionally, the other *.html file, which are not under pages folder, should not be shown in this page-listing page.

How should I do that?

Thanks a lot.

Manama answered 22/6, 2013 at 12:52 Comment(0)
R
1

There is nothing preventing you from doing so. In the above scenario, yourdomain.tld/pages/prent1/son1.html would be the URL of the parent1/son1 file.

Creating a nested listing, however, will be more complicated. You could either epscify that structure in the YAML Front Matter, or use posts.

pages
 |-> parent1
    |-> _posts/
      |-> index.html
      |-> son1.html
      |-> son2.html
 |-> parent2
    |->_posts
      |-> index.html

=> That way your files would be posts in the categories parent1 and parent2 and you could create the listing by displaying the categories and their contents.

If you really want to display a tree structure without using posts and categories, then you will need to do more black magic. But fortunately, Liquid offers a split filter which you could use to split the path of the site into chunks, e.g.

{% for page in site.pages %}            
    {{ page.url | split:'/' | join:'+'}}
{% endfor %}

Instead of joining them (this is purely for demonstartion), you'd want to populate an array which holds the tree structure and then later on iterate over that array to display the directory tree. It is possible, but not easy. And i don't think there is something readily available.

Probably writing a plugin is easier.

Ramayana answered 22/6, 2013 at 14:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.