_config.yml 中范围重叠的 Jekyll 问题
Jekyll issue with overlapping scopes in _config.yml
我在 _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
编辑:
阅读您的代码:
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
...
我在 _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
编辑:
阅读您的代码:
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
...