我想创建我自己的主题--mytheme for python-sphinx。
tree project
project
├── build
├── make.bat
├── Makefile
├── mytheme
│ ├── static
│ │ └── style.css
│ └── theme.conf
└── source
└── conf.pyTheme.conf格式的内容:
cat project/mytheme/theme.conf
[theme]
inherit = default
stylesheet = style.cssproject/source/conf.py中的Conent
cat project/source/conf.py
def setup(app):
app.add_stylesheet('static/style.css')
app.add_html_theme('mytheme', os.path.abspath(os.path.dirname(__file__)))
html_theme = 'mytheme'
html_theme_path = ['.'] 现在让我们将我所有的*.rst文件放在源代码中。
cd project
make html
Running Sphinx v2.4.4
loading pickled environment... done
Theme error:
theme 'mytheme' doesn't have "theme" setting
Makefile:19: recipe for target 'html' failed
make: *** [html] Error 2如何修复它?
发布于 2020-08-21 15:05:57
您可以使用两种互斥的方法--从文件系统中使用本地主题,同时注册主题,就像在作为Python PyPI包分发的主题中一样。
如果您想让某个主题成为Sphinx项目的一部分,那么使用这种特定于项目的主题的好地方是包含conf.py的目录中的_themes/,并在conf.py中设置html_theme = "mytheme"和html_theme_path = ["_themes"]。
_themes/
mytheme/
static/
css/
main.css
theme.conf
layout.html
conf.py
index.rst
second.rst
third.rst
...(借用自https://blog.documatt.com/sphinx-theming/themes.html#project-specific-themes)
完全删除数据块
def setup(app):
app.add_stylesheet('static/style.css')
app.add_html_theme('mytheme', os.path.abspath(os.path.dirname(__file__)))add_html_theme()它是以包的形式发布的主题。add_stylesheet()将添加额外的(而不是替换现有的)样式表。主题主样式表在他们的theme.conf stylesheet选项中。
我在你的例子中看到的最后一个问题是你的主题继承自default主题。它可以工作,它看起来是classic主题(https://www.sphinx-doc.org/en/master/usage/theming.html#builtin-themes)的旧名称,但使用它的官方名称- classic。
https://stackoverflow.com/questions/63469706
复制相似问题