如何有条件配置Docusaurus config Keys?

发布于 2025-02-07 02:27:53 字数 737 浏览 3 评论 0原文

如果用户需要根据某种条件配置可选的Docusaurus配置密钥,那么在Docusaurus.config.js文件中解决它的最佳方法是什么?例如:

module.exports = {
  /* If condition is true then */
  showLastUpdateAuthor: true,
  /* otherwise set it to false */
  //Other config key value...

}

这是我尝试的,它起作用。有更好的方法来处理这一点吗? 通过差异语法讨论在这里

const branch = require('child_process')
  .execSync('git branch --show-current')
  .toString().trim();

module.exports = {
    ...(branch != 'main') ? {showLastUpdateAuthor: true,}:{showLastUpdateAuthor: false,},
    //Other config key value...
}

If a user needs to configure an optional docusaurus config key based on some condition, what is the best way to address it in docusaurus.config.js file? For example:

module.exports = {
  /* If condition is true then */
  showLastUpdateAuthor: true,
  /* otherwise set it to false */
  //Other config key value...

}

Here is what I tried and it worked. Is there a better way to handle this?
Insights via Spread Syntax discussed 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...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场信仰旅途 2025-02-14 02:27:53

它起作用。还有其他更好的方法吗?

const branch = require('child_process')
  .execSync('git branch --show-current')
  .toString().trim();

module.exports = {
    ...(branch != 'main') ? {showLastUpdateAuthor: true,}:{showLastUpdateAuthor: false,},
    //Other config key value...
}

It worked. Any other better way?

const branch = require('child_process')
  .execSync('git branch --show-current')
  .toString().trim();

module.exports = {
    ...(branch != 'main') ? {showLastUpdateAuthor: true,}:{showLastUpdateAuthor: false,},
    //Other config key value...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文