如何访问集合中的静态文件?

How to access static files in a collection?

如何访问集合中的静态文件?

我(我认为)已按照

上的说明进行操作

https://jekyllrb.com/docs/collections/

我创建了目录 ./_test 和静态文件 ./_test/a./_test/b 并在 _config.yml:

中添加了相应的集合条目
collections:
  - test

在此之后,我无法使用 site.test.files 获取包含文件 ./_test/a./_test/b 的数组(根据我对上述 Jekyll 文档的解释,这应该是可能的)。

(我使用的是 GitHub-Pages 提供的 Jekyll 版本。)

假设你同时拥有,一些带有 yaml 前端内容的文件和静态文件 不会被 jekyll 处理。这些文件可以通过以下方式访问:

  • 前题文件:

    {% assign test_docs = site.test %}
    {{ test_docs }}
    
  • 静态文件:

    {% assign test_coll = site.collections | where: "label", "test" | first %}
    {{ test_coll.files }}
    

正如您明确要求静态文件一样,在上面的代码中 {{ test_coll.files }} 包含包含文件 /_test/a/_test/b 的数组。 但是,前提是这些文件没有 yaml front matter。