【发布时间】:2022-06-13 19:17:09
【问题描述】:
如果用户需要根据某些条件配置可选的 docusaurus 配置键,那么在 docusaurus.config.js 文件中解决它的最佳方法是什么?例如:
module.exports = {
/* If condition is true then */
showLastUpdateAuthor: true,
/* otherwise set it to false */
//Other config key value...
}
这是我尝试过的,它奏效了。有没有更好的方法来处理这个? 通过传播语法讨论的见解here。
const branch = require('child_process')
.execSync('git branch --show-current')
.toString().trim();
module.exports = {
...(branch != 'main') ? {showLastUpdateAuthor: true,}:{showLastUpdateAuthor: false,},
//Other config key value...
}
【问题讨论】:
标签: conditional-statements config docusaurus