静态文件是指不包含任何 front matter 的文件。其中包括图像、PDFs和其他未渲染的内容。
它们可在Liquid中通过 site.static_files
访问,并包含以下元数据:
Variable | Description |
---|---|
| The relative path to the file, e.g. |
| The `Time` the file was last modified, e.g. |
| The string name of the file e.g. |
| The string basename of the file e.g. |
| The extension name for the file, e.g. |
======================================== |
请注意,在上表中,file
可以是任何内容。它是一个任意设置的变量,用于您自己的逻辑(例如for循环)。它不是全局网站或页面的变量。
Add front matter to static files
虽然不能直接将 front matter 值添加到静态文件中,但可以通过配置文件中的 defaults property 设置 front matter 的值。当Jekyll构建网站时,它将使用您设置的 front matter 值。
这是一个示例:
在 _config.yml
文件中,将以下值添加到 defaults
属性:
defaults:
- scope:
path: "assets/img"
values:
image: true
这假设您的Jekyll站点有一个 assets/img
的文件夹路径,其中存储了图像(静态文件)。当Jekyll构建网站时,它会将每个图像视为具有 front matter 值:image: true
。
假设您想列出 assets/img
中包含的所有图像资产。您可以使用此for循环来查找 static_files
对象,并获取所有具有此 front matter 属性的静态文件:
{% assign image_files = site.static_files | where: "image", true %}
{% for myimage in image_files %}
{{ myimage.path }}
{% endfor %}
当你构建你的网站时,输出会列出每个符合这个 front matter 条件的文件路径。