配置級聯
配置級聯。
您可以配置站點將 front matter 值級聯到首頁及其任何子頁面。但是,如果子頁面已經定義了該字段,或者更近的祖先 節點 已經通過其 front matter 的 cascade 鍵級聯了相同字段的值,則這種級聯將被阻止。
您也可以在頁面的 front matter 中級聯行為。詳見 詳情。
例如,要將 “color” 參數級聯到首頁及其所有子頁面:
cascade:
params:
color: red
[cascade]
[cascade.params]
color = 'red'
{
"cascade": {
"params": {
"color": "red"
}
}
}
目標
target1 關鍵字允許您定位特定頁面或 環境。例如,要將 “color” 參數級聯到 “articles” 部分中的頁面,包括 “articles” 部分頁面本身:
cascade:
params:
color: red
target:
path: '{/articles,/articles/**}'
[cascade]
[cascade.params]
color = 'red'
[cascade.target]
path = '{/articles,/articles/**}'
{
"cascade": {
"params": {
"color": "red"
},
"target": {
"path": "{/articles,/articles/**}"
}
}
}
使用這些關鍵字的任何組合來定位頁面和/或環境:
- environment
- (
string) 匹配構建 環境 的 glob 模式。例如:{staging,production}。 - kind
- (
string) 匹配 頁面類型 的 glob 模式。例如:{taxonomy,term}。 - lang
- (
string) 匹配 頁面語言 的 glob 模式。例如:{en,de}。 - path
- (
string) 匹配頁面 邏輯路徑 的 glob 模式。例如:{/books,/books/**}。
數組
定義級聯參數數組以將不同的值應用於不同的目標。例如:
cascade:
- params:
color: red
target:
kind: page
lang: '{en,de}'
path: /books/**
- params:
color: blue
target:
environment: production
kind: page
path: /films/**
[[cascade]]
[cascade.params]
color = 'red'
[cascade.target]
kind = 'page'
lang = '{en,de}'
path = '/books/**'
[[cascade]]
[cascade.params]
color = 'blue'
[cascade.target]
environment = 'production'
kind = 'page'
path = '/films/**'
{
"cascade": [
{
"params": {
"color": "red"
},
"target": {
"kind": "page",
"lang": "{en,de}",
"path": "/books/**"
}
},
{
"params": {
"color": "blue"
},
"target": {
"environment": "production",
"kind": "page",
"path": "/films/**"
}
}
]
}
-
target的_target別名已棄用,將在未來版本中刪除。 ↩︎