首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >主题主题-名称没有“主题”设置自定义我的主题在sphinx?

主题主题-名称没有“主题”设置自定义我的主题在sphinx?
EN

Stack Overflow用户
提问于 2020-08-18 21:29:21
回答 1查看 148关注 0票数 1

我想创建我自己的主题--mytheme for python-sphinx。

代码语言:javascript
复制
tree project
project
├── build
├── make.bat
├── Makefile
├── mytheme
│   ├── static
│   │   └── style.css
│   └── theme.conf
└── source
    └── conf.py

Theme.conf格式的内容:

代码语言:javascript
复制
cat  project/mytheme/theme.conf
[theme]
inherit = default
stylesheet = style.css

project/source/conf.py中的Conent

代码语言:javascript
复制
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文件放在源代码中。

代码语言:javascript
复制
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

如何修复它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-21 15:05:57

您可以使用两种互斥的方法--从文件系统中使用本地主题,同时注册主题,就像在作为Python PyPI包分发的主题中一样。

如果您想让某个主题成为Sphinx项目的一部分,那么使用这种特定于项目的主题的好地方是包含conf.py的目录中的_themes/,并在conf.py中设置html_theme = "mytheme"html_theme_path = ["_themes"]

代码语言:javascript
复制
_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)

完全删除数据块

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63469706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档