Show pages under one folder in Jekyll?

我的未来我决定 提交于 2019-12-06 01:00:02

问题


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.


回答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.



来源:https://stackoverflow.com/questions/17250939/show-pages-under-one-folder-in-jekyll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!