静态文件不会出现在 Jekyll 中

Static files don't show up in Jekyll

我正在尝试按照 Jekyll 文档中的以下基本步骤在我的页面中打印我的静态图像:

https://jekyllrb.com/docs/static-files/

我的文件在 assets/img 中,我的配置文件有这些行(space 缩进)

  defaults:
  - scope:
      path: "assets/img"
    values:
      image: true

我有一个全新的 Jekyll 网站。现在在我的 about.md 页面中,我想打印所有图像:

{% assign image_files = site.static_files | where: "image", true %}

{% for myimage in image_files %}
  {{ myimage.path }}
{% endfor %}

不用说它什么都不打印。

虽然我可以打印 {{ site.static_files | inspect }} 包括所有文件:字体、图像、zip 等我不能打印 image_files 变量,也不能打印 myimage

发生了什么事?

在根项目中,在 assets 文件夹中创建文件夹 assetsimg。 将您的图像放入 img

例子:

myblog
.
├── 404.html
├── about.md
├── assets
│   └── img
│       └── filename.png

_config.yml:

defaults:
  - scope:
      path: "assets/img"
    values:
      image: true

在您的帖子中,例如:about.md,放置类似这样的内容:

{% assign image_files = site.static_files | where: "image", true %}
{% for myimage in image_files %}
  ![{{myimage.name}}]({{ myimage.path }})
{% endfor %}