如何在Sphinx主题或扩展构建事件中设置配置值?

发布于 2025-02-07 16:51:23 字数 851 浏览 0 评论 0原文

我正在构建一个子类主题,该主题是另一个主题,并在sphinx中设置了几个默认配置值(例如,html_theme_options的值的子集)。

我尝试编写回调事件函数以读取 app.config 如果不存在,则设置一个变量,如这样:

def setup(app):
    app.config.html_theme_options["option"] = "value"

但是,“ value”似乎并未传播到Sphinx构建过程中的其他阶段。如果我检查app.config.html_theme_options,在将其重置为主题之前,我再次具有原始默认值。

我在config-initedbuilder-inited 构建事件,但在任何一种情况下似乎都不起作用。有人知道如何通过自己的主题或扩展而过度乘坐狮身人面像默认值?

I am building a Sphinx theme that sub-classes another theme, and sets several default configuration values in Sphinx (for example, a subset of values of html_theme_options).

I have tried writing a callback event function to read app.config and set a variable if it does not exist, like this:

def setup(app):
    app.config.html_theme_options["option"] = "value"

However, "value" does not seem to propagate to other stages in the Sphinx build process. If I inspect app.config.html_theme_options, I once again have the original default value before I reset it in my theme.

I have tried the same pattern in the config-inited and builder-inited build events, but it doesn't seem to work in either case. Does anybody know how to over-ride Sphinx defaults via your own theme or extension?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文