⚠️The latest release refactored our HTML, so double-check your custom CSS rules!⚠️

Sphinx 配置

Sphinx 配置#

本篇将列出一些常用的配置。

Path 设置#

如果 extensions (或要用 sphinx.ext.autodoc 文档的模块)在另一个目录中,将这些目录添加到 sys.path。如果目录是相对于文档根目录的,那么使用 pathlib.Path.absolute() 将其设置为绝对目录,如下面所示:

import sys
from pathlib import Path

if sys.platform == 'win32':
    import asyncio
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

ROOT = Path(__file__).parent.absolute()
sys.path.extend([str(ROOT)])

项目信息#

项目信息的一般信息:

project = 'xyz' # 记录的项目名称
copyright = '2022, xinetzone' # 版权声明。
author = 'xinetzone'  # 该文档的作者姓名。默认值是 ``'unknown'``。

项目的主版本使用 version,用来替代 |version|。例如,对于 Python 文档,这可能是 3.10 之类的。release 表示项目的完整版本 alpha/beta/rc tags,用来替代 |release|,例如在 HTML 模板中。例如,对于 Python 文档,这可能是 2.6.0rc1。示例如下:

version = '0.0.1'
release = '0.0.1rc1'

通用配置#

extensions 字符串列表

# 在这里添加任何 Sphinx 插件模块名,作为字符串。
# 它们可以是 Sphinx 自带的插件(名为 ``sphinx.ext.*``),也可以是你自定义的插件。
# 配置文件(``conf.py``)本身可以是插件;为此,你只需要在其中提供 {func}`setup` 函数。
extensions = [
]

# 根文件的文件名,即包含根 ``toctree`` 指令的文件。默认为 ``'index'``。
root_doc = 'index' 

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'zh_CN'

# 相对于源目录的模式列表,匹配在寻找源文件时要忽略的文件和目录。
# 此模式也影响 ``html_static_path`` 和 ``html_extra_path``。
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']