循环遍历_posts子文件夹中的文件 - Jekyll

问题描述 投票:0回答:2

我使用Prose.io作为github的CMS。我已将根目录设置为/ _posts。在/ _posts我创建了一个文件夹“staticpages”,它包含一些带文本的markdown文件。我可以循环浏览这些文件吗?我似乎无法弄清楚如何。

所以我的文件树看起来像:

root
   |
   _posts/
      |
      staticpages/
         |
         myfile.md

我想:

{% for pages in posts.staticpages %} {{ page.title }} {% endfor %}
jekyll liquid templating
2个回答
3
投票

干得好: 在你指定的_config.yml

defaults:
  - scope:
      path: "_posts/staticpages"
    values:
      static: "true"

并在您的布局文件(或页面)中过滤帖子并循环:

{% assign posts = site.posts | where:"static", "true" %}
{% for post in posts %}...

这对我很有用......


0
投票

您可以通过在URL中设置文件夹来浏览到该文件夹​​。如果默认URL为:

http://prose.io/#<account>/<repository>/

然后,您可以在URL中添加分支和文件夹相对路径:

http://prose.io/#<account>/<repository>/tree/master/_posts/staticpages

© www.soinside.com 2019 - 2024. All rights reserved.