gpt4 book ai didi

python-sphinx - ReadTheDocs 和 localhost 之间的渲染差异

转载 作者:行者123 更新时间:2023-12-04 01:35:29 32 4
gpt4 key购买 nike

我刚刚将我的文档从 Github 上传到 ReadTheDocs,我发现它在 ReadTheDocs 和我的本地机器上呈现完全不同。我正在使用最新的 sphinx_rtd_theme在我的本地机器上。

这是我本地机器上的显示:

enter image description here

这是 ReadTheDocs 上的渲染:

enter image description here

我在 Chrome、Firefox 和 Microsoft Edge 上尝试过,结果相同,所以它似乎不是浏览器问题。

这是我的 conf.py 的副本:

# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import os


# -- Project information -----------------------------------------------------

project = 'OrderedTree'
project_title = 'Ordered Tree'
copyright = '2018, Jonathan Gossage'
author = 'Jonathan Gossage'

# The short X.Y version
version = '0.0'
# The full version, including alpha/beta/rc tags
release = '0.0.1'


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# 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.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
]

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

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# 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 = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# Elements to be included at yhe start of each document file
rst_prolog = """
.. |br| raw:: html

<br />

.. |pn| replace:: {}
.. |pt| replace:: {}
""".format(project, project_title)


# -- 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 = 'sphinx_rtd_theme'
on_rtd = os.environ.get('READTHEDOCS') == 'True'
if on_rtd:
html_theme = 'default'
else:
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# 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".
if on_rtd:
html_static_path = []
else:
html_static_path = ['_static']

html_context = { # Specify the css file to use
'css_files': ['_static/theme_overrides.css',]
}

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = '{}doc'.format(project)


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, '{}.tex'.format(project), '{} Documentation'.format(project_title),
'{}'.format(author), 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, '{}'.format(project), '{} Documentation'.format(project_title),
[author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, '{}'.format(project), '{} Documentation'.format(project_title),
author, '{}'.format(project), 'One line description of project.',
'Miscellaneous'),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project_title
epub_author = author
epub_publisher = author
epub_copyright = copyright

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']


# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}

# -- Options for todo extension ----------------------------------------------

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True

我已经确定了导致问​​题的原因,但我不知道它为什么会发生或如何解决它。我正在使用来自 Creative Commons 的 HTML 样板片段,它标识了管理文档使用的许可证。我拿了底座 sphinx_rtd_theme Footer.html并将此片段添加到其中并使用修改后的 Footer.html覆盖基本副本。片段如下:
    <br /> <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">
<img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a>
<br />
<p>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>
</p>

该片段实际上有效,因为此 HTML 在 ReadTheDocs 上正确呈现,但其余格式消失。

我需要做什么才能在 ReadTheDocs 上获得本地显示?

最佳答案

听起来像静态 Assets 没有被复制到 RTD 上。让我们看看build log , 下 python /home/docs/checkouts/readthedocs.org/user_builds/orderedtree/envs/latest/bin/sphinx-build -T -E -b readthedocs -d _build/doctrees-readthedocs -D language=en . _build/html :

copying static files... WARNING: html_static_path entry '/home/docs/checkouts/readthedocs.org/readthedocs/templates/sphinx/_static' does not exist

你知道吗? That error sounds strangely familiar for some reason... .

让我们看看您的 conf.py 中的设置:
html_static_path = ['_static']

尝试将其更改为:
html_static_path = []

似乎适用于大约十几个其他用户。

关于python-sphinx - ReadTheDocs 和 localhost 之间的渲染差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50080481/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com