我认为设置relative_directory
(Jekyll Collection Docs)
(github PR)属性设置将帮助我保持我的文件有条理而不影响我想要的输出,但它似乎被忽略/不用于生成文件.我不希望我的集合在根目录中,因为我发现在_assets,_data,_includes,_layouts和其他附近有~10个集合文件夹会让人感到困惑.
欢迎修复或替代解决方案,只要输出相同,并且我的页面在他们自己的目录中,而不需要在每个页面上放置永久链接.
_config.yaml
collections:
root:
relative_directory: '_pages/root'
output: true
permalink: /:path.html
root-worthy:
relative_directory: '_pages/root-worthy'
output: true
permalink: /:path.html
docs:
relative_directory: '_pages/docs'
output: true
permalink: /docs/:path.html
目录结构:
├── ...
├── _layouts
├── _pages
│ ├── root
│ │ ├── about.html
│ │ └── contact.html
│ ├── root_worthy
│ │ ├── quickstart.html
│ │ └── seo-worthy-page.html
│ └── docs
│ ├── errors.html
│ └── api.html
├── _posts
└── index.html
期望的输出:
├── ...
├── _site
│ ├── about.html
│ ├── contact.html
│ ├── quickstart.html
│ ├── seo-worthy-page.html
│ └── docs
│ ├── errors.html
│ └── api.html
└── ...
最佳答案 你提到的公关似乎仍然没有合并.
对于3.1.6和下一个3.2,jekyll code is still:
@relative_directory ||= "_#{label}"
但是the requester made a plugin看起来像这样:
_plugins / collection_relative_directory.rb
module Jekyll
class Collection
def relative_directory
@relative_directory ||= (metadata['relative_directory'] && site.in_source_dir(metadata['relative_directory']) || "_#{label}")
end
end
end