更多 Sphinx 客製化¶
除了核心 Sphinx 提供的功能之外,客製化文件主要有兩種方式:擴充功能和主題。
啟用內建擴充功能¶
除了這些設定值之外,您還可以通過使用擴充功能來進一步客製化 Sphinx。 Sphinx 內建了幾個擴充功能,社群也維護了更多第三方擴充功能。
例如,要啟用 sphinx.ext.duration
擴充功能,請找到 conf.py
中的 extensions
列表,並依照以下方式新增一個元素
docs/source/conf.py¶
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.duration',
]
之後,每次您產生文件時,都會在主控台輸出的末尾看到一份簡短的持續時間報告,就像這樣
(.venv) $ make html
...
The HTML pages are in build/html.
====================== slowest reading durations =======================
0.042 temp/source/index
使用第三方 HTML 主題¶
另一方面,主題是一種客製化文件外觀的方式。 Sphinx 有幾個內建主題,也有第三方主題。
例如,要在您的 HTML 文件中使用 Furo 第三方主題,您首先需要在您的 Python 虛擬環境中使用 pip
安裝它,就像這樣
(.venv) $ pip install furo
然後,找到您的 conf.py
上的 html_theme
變數,並依照以下方式替換其值
docs/source/conf.py¶
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'furo'
透過此變更,您會注意到您的 HTML 文件現在有了新的外觀

使用 Furo 主題的 Lumache HTML 文件¶
現在是時候擴展敘述式文件並將其拆分為多個文件了。