Dev*_*day 5 html liquid jekyll
我正在完成我的网站重新设计,只需要完成我的投资组合页面。我想使用子目录/子页面,而不是使用文章作为投资组合条目:
...
work
project
index.html
project-2
index.html
index.html
...
Run Code Online (Sandbox Code Playgroud)
我想遍历列表中的这些子页面以显示在work/index.html. 类似于:
<ul>
{% for page in site.work.pages %}
<li>
<figure>
<img src="/img/foo.jpg" alt="foo">
</figure>
</li>
{% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点?
Jekyll 并不像您的示例中那样简单地支持这一点,但是它会在 2.0 中出现。
\n\n您可以将键/值对添加到子页面的 YAML 标题中,以表示它应该出现在主索引页面上。我有一个类似的设置,用于定义哪些页面应显示在网站的主导航中。
\n\n---\ngroup: work\n---\nRun Code Online (Sandbox Code Playgroud)\n\n<ul>\n{% for node in site.pages %}\n {% if \'work\' == node.group %}\n <li><a href="{{node.url}}">{{node.title}}</a></li>\n {% endif %}\n{% endfor %}\n</ul>\nRun Code Online (Sandbox Code Playgroud)\n\n如果您更改 if 条件来进行 URL 的子字符串匹配,您也许可以避免需要 group 属性,但此解决方案更容易理解。
\n