本文介绍了如何将所有文件包含在Jekyll的文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Jekyll中,您可以执行以下操作来包含文件:
In Jekyll you can include a file by doing:
{% include some-folder/some-file.html %}
如果将更多文件添加到文件夹,则必须手动添加它们:
If you add more files to the folder you have to manually add them:
{% include some-folder/some-file-2.html %}
{% include some-folder/some-file-3.html %}
{% include some-folder/some-file-4.html %}
Jekyll中是否可以自动将所有文件包含在文件夹中?
Is there a way in Jekyll to include all files in a folder automatically?
推荐答案
我找到了一种方法来包括当前文件夹中所有文件的内容,而不包括当前文件.
I have found a way to include the content of all files in the current folder not including the current file.
{% assign parent_path = page.path | split:'/' | last %}
{% assign parent_path = page.path | remove: parent_path %}
{% for file in site.static_files %}
{% if file.path contains parent_path %}
{% assign file_name = file.path | remove: parent_path | remove: "/" %}
{% include_relative {{ file_name }} %}
{% endif %}
{% endfor %}
我的设置原因:我有一个很大的markdown文件(main.md
),其中包含很多信息,因此我需要一种将内容移动到单独文件中并将其包含在main.md
.
Reason for my setup: I have a large markdown file (main.md
) that contains a lot of information, so I needed a way to move the content into separate files and included them with main.md
.
这篇关于如何将所有文件包含在Jekyll的文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!