在Jekyll中的一个文件夹下显示页面? [英] Show pages under one folder in Jekyll?

查看:136
本文介绍了在Jekyll中的一个文件夹下显示页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为管理Jekyll页面的本机方式(即通过在根文件夹下创建.md文件/文件夹)有点混乱.

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.

因此,我想将要显示的每个页面放入名为"pages"的文件夹中.另外,我希望这些页面具有级联结构:说我的文件夹是否具有以下结构:

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

此外,不在页面文件夹下的其他* .html文件也不应显示在此页面列表页面中.

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

我应该怎么做?

非常感谢.

推荐答案

没有什么可以阻止您这样做的.在上述情况下,yourdomain.tld/pages/prent1/son1.html将是parent1/son1文件的URL.

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.

但是,创建嵌套列表将更加复杂.您可以在YAML前端问题中阐明该结构,也可以使用帖子.

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

=>这样,您的文件将被归入parent1和parent2类别中,并且可以通过显示类别及其内容来创建列表.

=> 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.

如果您真的想显示树结构而不使用帖子和类别,那么您将需要做更多的黑魔法.但幸运的是,Liquid提供了split过滤器,您可以使用该过滤器将网站路径拆分为多个块,例如

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.

编写插件可能更容易.

这篇关于在Jekyll中的一个文件夹下显示页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆