Show pages under one folder in Jekyll?

I think Jekyll's own way of managing pages, i.e. by creating a .md file / folders in the root folder is a bit confusing.

So I want to put every page that I want to show in a folder called "pages". In addition, I would like these pages to have a cascading structure: let's say if my folder has a structure:

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

Then there should be something like this on the page listing page:

 page listing * parent1 * son1 * son2 * parent2 

In addition, another * .html file that is not located in the folder with folders should not be displayed on this page with a list of pages.

How can I do it?

Thank you very much.

+6
source share
1 answer

There is nothing to stop you from doing this. In the above script, yourdomain.tld / pages / prent1 / son1.html will be the URL of the parent1 / son1 file.

Creating a nested list, however, will be more complicated. You can either type this structure into the YAML Front Matter, or use messages.

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

=> This way your files will be messages in the categories parent1 and parent2, and you can create a list by specifying the categories and their contents.

If you really want to display the tree structure without using messages and categories, you will need to do more black magic. But, fortunately, Liquid offers a split filter, which can be used to split the site path into pieces, for example.

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

Instead of joining them (this is just for demonstration), you want to populate an array that contains a tree structure, and then iterate over that array to display the directory tree. It is possible, but not easy. And I do not think that there is something easily accessible.

It’s probably easier to write a plugin.

+1
source

Source: https://habr.com/ru/post/947892/


All Articles