如何有条件配置Docusaurus config Keys?
如果用户需要根据某种条件配置可选的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它起作用。还有其他更好的方法吗?
It worked. Any other better way?