Ruby 在不同目录中使用Jekyll for循环
我正在使用Jekyll建立我的博客,最初计划只在主页上使用Jekyll。正因为如此,我在各自的目录中创建了其他不变的html页面,它们工作得很好。然而,我最近一直在考虑制作一个单独的页面来列出我到目前为止发表的所有帖子,因此需要参考主站点的帖子 我的项目结构如下所示:Ruby 在不同目录中使用Jekyll for循环,ruby,jekyll,directory-structure,Ruby,Jekyll,Directory Structure,我正在使用Jekyll建立我的博客,最初计划只在主页上使用Jekyll。正因为如此,我在各自的目录中创建了其他不变的html页面,它们工作得很好。然而,我最近一直在考虑制作一个单独的页面来列出我到目前为止发表的所有帖子,因此需要参考主站点的帖子 我的项目结构如下所示: _includes/ footer.html header.html sidebar.html _layouts/ default.html posts.html _posts/ .
_includes/
footer.html
header.html
sidebar.html
_layouts/
default.html
posts.html
_posts/
...
_site/
...
about/
index.html
archive/
index.html
css/
style.css
resume/
index.html
_config.yml
index.html
...
<h2>The Archive.</h2>
{% for post in site.posts %}
<h4><a href="{{ post.url }}">{{ post.title }}</a></h4>
<p><small>{{ post.date | date: "%B %e, %Y" }}</small></p>
{% endfor %}
...
我想列出我在archive/index.html页面上发表的所有帖子。我通过以下操作尝试了这一点:
_includes/
footer.html
header.html
sidebar.html
_layouts/
default.html
posts.html
_posts/
...
_site/
...
about/
index.html
archive/
index.html
css/
style.css
resume/
index.html
_config.yml
index.html
...
<h2>The Archive.</h2>
{% for post in site.posts %}
<h4><a href="{{ post.url }}">{{ post.title }}</a></h4>
<p><small>{{ post.date | date: "%B %e, %Y" }}</small></p>
{% endfor %}
...
但是,该archive/index.html页面仅将上述内容呈现为文本
我还尝试在归档目录中创建一个全新的Jekyll目录结构,但这似乎也不起作用
我如何才能使archive/index.html页面识别出列出我网站所有帖子的for循环?我已经完成了您的回购,这个archive/index.html工作得很好:
---
layout: default
---
<h2>The Archive.</h2>
{% for post in site.posts %}
<h4><a href="{{ post.url }}">{{ post.title }}</a></h4>
<p><small>{{ post.date | date: "%B %e, %Y" }}</small></p>
{% endfor %}
啊,忘了前面的事。这并没有完全解决我的问题,因为这迫使我使用default.html样式,但是制作一个新的布局应该可以解决它。谢谢事实上,只要在html文件的开头使用---分隔符,我就可以完全按照我喜欢的方式构造一个页面,并且for循环仍然可以识别。