配置级联
配置级联。
您可以配置站点将 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别名已弃用,将在未来版本中删除。 ↩︎