【发布时间】:2016-12-26 06:29:55
【问题描述】:
目标
根据目录结构让 Jekyll 帖子有自己的分类。
例如)_post/category1/category2/post-content.md 必须有 ['category1', 'category2'] 的类别(我猜 Jekyll 将类别作为数组处理)。
关键是,1)无需在Front Matter 中指定类别,2)按目录结构自动对每个帖子进行分类。
说明
官方 Jekyll 文档说Categories are derived from the directory structure above the _post directory. For example, a post at /work/code/_posts/2008-12-24-closures.md would have this field set to ['work', 'code'].
https://jekyllrb.com/docs/variables/
如果可能的话,我会很高兴地使用这个功能。问题是,我不知道如何使
_postdir 位于 in 其他目录中。我认为_post目录必须在根目录中,所以对我来说,将帖子定位在/work/code/_posts/2008-12-24-closures.md这样的路径中似乎是不可能的。是否可以?还是不可能?如果
1.是不可能,我如何为每个帖子匹配类别和目录结构?我不想为每个帖子手动执行此操作。
我尝试使用{{ page.path }}使其自动化,但我遇到了两个问题。 1) 不确定Liquid(template engine)是否支持完整的 ruby 功能,例如File.basename进行解析。 2) 不确定Front Matter中是否可以进行解析等代码。例如,我在Front Matter中尝试了categories: {{ page.path | array_to_sentence_string }},但结果出错了。
这些问题的任何解决方案?还是没有办法?
【问题讨论】: