配置#
配置分两层:
theme.toml中的默认值(随包发布,不需要站点重复声明)站点
conf.py的html_theme_options(只写覆盖项)
站点覆盖示例:
html_theme = "mystx"
html_theme_options = {
"book_nav_scope": "book",
"book_nav_depth": 3,
"book_content_width": "52rem",
}
书籍层选项#
选项 |
类型 |
默认 |
作用 |
|---|---|---|---|
|
str |
|
|
|
int |
|
侧栏初始展开层数;默认只展开顶层,当前章节自动展开 |
|
str |
|
正文最大宽度,写入 CSS 变量 |
|
list |
6 个按钮 |
页眉按钮及顺序;无仓库信息时仅保留下载与全屏 |
|
bool |
|
脚注转边注;正文以 |
|
list |
3 项 |
内容页脚条目;置空则回退 pydata-sphinx-theme 的页脚 |
列表选项既可以写字符串(逗号分隔),也可以写列表:
html_theme_options = {
"book_header_buttons": "download, source, edit",
# 等价于 ["download", "source", "edit"]
}
页眉工具箱#
book_header_buttons 按列表顺序渲染,支持六个值:
download:下载当前页源文件(需html_copy_source)fullscreen:全屏切换(主题自带脚本)repo:仓库首页edit:在线编辑source:查看源文件issue:新建 issue
后四项需要 html_context 提供仓库坐标(与 pydata-sphinx-theme 的编辑链接约定一致):
html_context = {
"github_user": "xinetzone",
"github_repo": "mystx",
"github_version": "main",
"doc_path": "doc",
}
GitLab / Bitbucket 同理,换成对应的 gitlab_* / bitbucket_* 键。坐标不完整时,
这四项自动不渲染,不报错。
边注#
book_use_sidenotes 打开后,所有脚注都被搬到引用点右侧的留白:
html_theme_options = {
"book_use_sidenotes": True,
}
宽屏(>=1400px)下含边注的页面会隐藏右侧页内目录,把这块区域让给边注;
窄屏下边注默认收起,点编号展开。块级内容用 {margin} 指令,它不受该开关影响。
细节见 侧栏注释。
页脚#
book_footer_items 按顺序渲染,支持 author / copyright /
last-updated:
html_theme_options = {
"book_footer_items": ["copyright", "last-updated"],
}
author 与 copyright 缺省时取 conf.py 的同名字段;last-updated 需要
html_last_updated_fmt。数据缺失的条目自动跳过,不报错。置空列表则整体回退
pydata-sphinx-theme 的原生页脚,footer_start / footer_center /
footer_end 随之恢复生效。
继承自基座的选项#
navbar_*、secondary_sidebar_items、navigation_depth、
show_nav_level、collapse_navigation、icon_links、switcher 等
均直接透传给 pydata-sphinx-theme,语义与其文档一致。
mystx 的默认值只做三处改动:
navbar_start/navbar_center/navbar_end/navbar_persistent置空article_header_start置空(去掉面包屑)secondary_sidebar_items只保留page-toc
要恢复顶部导航,显式赋值即可:
html_theme_options = {
"navbar_center": ["navbar-nav"],
}
页内覆盖#
PST 的页面级元数据仍然有效,例如去掉某页的右侧栏:
---
html_theme.sidebar_secondary.remove: true
---
主题名#
html_theme = "mystx"。若同时安装了 pydata_sphinx_theme,两者互不冲突:
mystx 只在自己的模板目录里覆盖,其余全部回退到基座。