【问题标题】:How to configure docusaurus config keys conditionally?如何有条件地配置 docusaurus 配置键?
【发布时间】: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


    【解决方案1】:

    成功了。还有其他更好的方法吗?

    const branch = require('child_process')
      .execSync('git branch --show-current')
      .toString().trim();
    
    module.exports = {
        ...(branch != 'main') ? {showLastUpdateAuthor: true,}:{showLastUpdateAuthor: false,},
        //Other config key value...
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-30
      • 2013-11-07
      • 2020-05-09
      • 2016-05-11
      • 1970-01-01
      • 2010-09-25
      • 2015-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多