自定义 Sphinx 以避免生成搜索框

Customizing Sphinx to avoid generating search box

是否有一种简单的方法(即,无需创建全新的主题)来自定义 Sphinx,使其生成 HTML 个没有搜索框的页面?

您可以通过自定义(或者我应该说禁用)搜索框模板来实现。

  1. 在conf.py中添加这一行:

    templates_path = ["templates"]
    
  2. 在您的 Sphinx 项目目录中创建一个名为 templates 的文件夹。

  3. 在该文件夹中,添加一个名为 searchbox.html 的空文件。这会覆盖默认模板文件(位于安装 Sphinx 的 sphinx/themes/basic 中)。

我在阅读 alabaster theme documentation 时发现的另一种方法是明确列出 conf.py 文件中需要哪些(如果有的话)侧边栏。例如,将此片段包含在 conf.py:

html_theme = 'alabaster'
html_sidebars = {
    '**': [
        'about.html',
        'navigation.html',
        'searchbox.html',
    ]
}

生成搜索框;从该列表中删除 searchbox.html 然后构建生成相同的页面但没有框。 (更多信息可以在 the Sphinx documentation for the build-configuration file 找到。)