【问题标题】:Using a Jekyll for loop in a different directory在不同的目录中使用 Jekyll for 循环
【发布时间】:2014-11-10 20:31:00
【问题描述】:

我正在使用 Jekyll 构建我的博客,并且最初计划只使用 Jekyll 作为主页。因此,我在它们各自的目录中创建了其他不变的 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

我想列出我在archive/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循环来列出我网站的所有帖子?

【问题讨论】:

    标签: ruby jekyll directory-structure


    【解决方案1】:

    我已经分叉了你的回购,这个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 循环。
    猜你喜欢
    • 2022-08-19
    • 1970-01-01
    • 2023-04-03
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多