2017-03-31 68 views
1

我正在使用Jekyll在GitHub上创建一个静态页面,我已经设置了我的默认布局和index.html页面。Jekyll For Loop包括所有目录

我想创建一个名为'sections'的文件夹,并存储一些.html文件,这些文件基本上是我制作的指南中不同的部分。这样做的目的是让我可以使用Jekyll for循环将整个'部分'包含到我的主index.html中。我想将所有部分放在部分文件夹中,以使其更易于管理。

这可能吗?

+0

是的,这是可能的。 – marcanuy

回答

1

Jekyll的目录结构是不是你可以根据你的方便改变的东西。如果你想有每个html页面作为一个单独的页面在你的网站,你必须做的就是把你的html网页中_posts目录中的项目并使用for循环像这样包括在index.html自己的链接:

{% for post in site.posts %} 
    <!-- link to each post in index.html --> 
    <a href="{{ site.url }}{{ post.url }}">{{ post.title }}</a> 
{% endfor %} 

如果要将每个html文件的内容放入index.html,则不能使用_posts。在这种情况下,你需要使用_includes目录,这样做:

... 
{% include page1.html %} 
{% include page2.html %} 
{% include page3.html %} 
... 

Jekyll directory structure doc

+0

假设我在_posts内有* .html文件,我可以只包含所有主要的index.html文件吗? – Erdss4

+0

@ Erdss4编辑了答案。看一看。 –