【问题标题】:Jekyll loop pages by parent directoryJekyll 按父目录循环页面
【发布时间】:2014-08-26 13:00:33
【问题描述】:

我的 Jekyll 网站由文件夹中的页面组成。像这样:

modules
- week 1
-- topic 1
-- topic 2
-- topic 3
- week 2
-- topic 1
- week 3
-- topic 1

这是我的 Sublime 文件夹视图的屏幕截图:http://glui.me/?i=884mtx2vcyv7fjx/2014-08-26_at_11.26_AM.png/

我可以做一个简单的{% for page in site.pages %} 来输出站点中所有页面的平面列表,但我想保持该文件夹结构。

关于如何输出反映我所拥有的目录结构的列表的任何想法?

谢谢!

【问题讨论】:

    标签: jekyll


    【解决方案1】:

    此页面方案

    --modules
        |
        --schedule
        |  |--schedule-01.html
        |  |--schedule-02.html
        | 
        --week01
        |  |--topic-01.html
        |  |--topic-02.html
        |  |--topic-11.html
        |  
        --week02
        |  |--topic-01.html
        |  |--topic-02.html
        |
        --week11
        |  |--topic-01.html
        |  |--topic-02.html 
        |
        |...
    

    可以很好地排序并显示在菜单中

    示例页面模块/week01/topic-01.html

    ---
    title: Week 1 - Topic 01
    layout: page or any custome module layout
    menu: modules
    ---
    
    Topic 01 content
    

    最后是带有他的菜单的 modules.html 页面

    <h2>Modules list</h2>
    
    {% assign sorted = site.pages | sort: "url" %}
    <ul>
    {% for p in sorted %}
    {% if p.menu == "modules" %}
      <li><a href="{{ site.baseurl }}{{ p.url }}">{{ p.title }}</a></li>
    {% endif %}
    {% endfor %}
    </ul>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      相关资源
      最近更新 更多