当我在看文档时。我看到以下文件结构,
.
├── _config.yml
├── _drafts
| ├── begin-with-the-crazy-ideas.textile
| └── on-simplicity-in-technology.markdown
├── _includes
| ├── footer.html
| └── header.html
├── _layouts
| ├── default.html
| └── post.html
├── _posts
| ├── 2007-10-29-why-every-programmer-should-play-nethack.textile
| └── 2009-04-26-barcamp-boston-4-roundup.textile
├── _data
| └── members.yml
├── _site
├── .jekyll-metadata
└── index.html
当我需要在我的帖子中包含图片时。我应该把图片放在哪里才能使用
site.static_files
的功能提到 here (文档中的静态文件部分)?这样我就可以使用像 file.path
这样的变量和 file.modified_time
直接地。以前,当我使用 Jekyll 2.x 时,我通过创建自己的 Assets 目录来执行以下操作。
<link rel="stylesheet" href="{{ "/assets/css/index.css" | prepend: site.url }}">
最佳答案
假设您的图库图像的结构类似于
-img
-gallery
-image1.png
-image2.png
etc.
您可以在集合或页面中访问它们,如下所示:
{% for image in site.static_files %}
{% if image.path contains 'img/gallery' %}
<p>{{image.path}} - {{image.modified_time}}</p>
<img src="{{site.baseurl}}{{image.path}}">
{% endif %}
{% endfor %}
这会遍历所有静态文件并检查某个路径(在本例中为
img/gallery
)。您可以访问该文件的静态文件元数据。 (我在本例中将其命名为“图像”,但您可以在
for
关键字后任意命名)。我认为将这样的内容放在博客文章中并没有太大意义,而是放在
page
中。或 collection
.
关于jekyll - 我应该将静态文件放在 Jekyll 的哪个文件夹中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36448853/