2016-12-28 76 views
0

重疊的範圍,我有使用範圍的問題,在我的_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」對的範圍則不是這種情況。

我錯過了什麼?

編輯:

我傑奇項目的目錄結構看起來像這樣(我刪除unrelevant文件):

./ 
├──_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 

回答

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 
    ... 
+0

Thx爲您的答案。我在** en/_posts **和** fr/posts **(我編輯了我的問題以精確的目錄結構)中存儲我的帖子。我嘗試了你的建議,但它不起作用:英文帖子仍然有正確的佈局,而法語帖子沒有 – wasthishelpful

+0

編輯我的答案。你在** _ posts **中錯過了** s **。 –

+0

對不起,這是一個錯字,正如我的評論。帖子在** en/_posts **和** fr/_posts **中,這就是我在'_config.yml'中使用的路徑,就像你的回答 – wasthishelpful