我在_config.yml
文件中使用范围时遇到问题:
在多语言博客中,我想为所有帖子使用给定的布局,然后为每种语言定制具有更专业范围的永久链接。这是我的配置:
defaults:
-
# defaults for all files in the project
scope:
path: ""
values:
layout: my-page-layout
-
# defaults for all posts in the project
scope:
path: ""
type: posts
values:
layout: my-post-layout
-
# defaults for all english posts in the project
scope:
path: en
type: posts
values:
permalink: /en/:year/:month/:title/
-
# defaults for all french posts in the project
scope:
path: fr
type: posts
values:
permalink: /fr/:year/:month/:title/
路径en
下的英文帖子实际上有正确的布局(my-post-layout
),但不是路径fr
下具有默认布局(my-page-layout
的法语帖子)。
看起来对应于“fr / posts”对的范围会覆盖所有帖子的默认值,而对应于“en / posts”对的范围则不是这样。
我错过了什么?
修改
我的jekyll项目的目录结构如下所示(我删除了不相关的文件):
./
├──_layouts/
│ ├──my-page-layout.html
│ └──my-post-layout.html
│
├──en/
│ ├──_posts/
│ │ └──2016-12-01-my-post-in-english.md
│ │
│ └──my-page-in-english.html
│
├──fr/
│ ├──_posts/
│ │ └──2016-12-01-mon-post-en-français.md
│ │
│ └──ma-page-en-français.html
│
└──_config.yml
答案 0 :(得分:1)
编辑:
从您的代码中读取:
defaults:
-
scope:
path: ""
values:
layout: wasthishelpful-page
lang: en
-
scope:
path: fr
values:
lang: fr
-
scope:
path: ""
type: posts
values:
layout: wasthishelpful-post
-
scope:
path: en/_posts
values:
permalink: /en/:year/:month/:title/
-
scope:
path: fr/_posts
values:
permalink: /fr/:year/:month/:title/
从jekyll code开始,我们可以看到我们有一个优先级问题。
第二条规则适用于 / fr 路径,但不会被适用于 / 路径的第三条规则覆盖。
解决方案是通过反转它们在第二个规则之前声明你的第三个规则。
defaults:
-
scope:
path: ""
values:
layout: wasthishelpful-page
lang: en
-
scope:
path: ""
type: posts
values:
layout: wasthishelpful-post
-
scope:
path: fr
values:
lang: fr
...