mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4177 from tk0miya/improve_theme_sidebars
HTML themes can set up default sidebars through ``theme.conf``
This commit is contained in:
commit
215be8e5bd
1
CHANGES
1
CHANGES
@ -38,6 +38,7 @@ Features added
|
|||||||
* #1448: qthelp: Add new config value; :confval:`qthelp_namespace`
|
* #1448: qthelp: Add new config value; :confval:`qthelp_namespace`
|
||||||
* #4140: html themes: Make body tag inheritable
|
* #4140: html themes: Make body tag inheritable
|
||||||
* #4168: improve zh search with jieba
|
* #4168: improve zh search with jieba
|
||||||
|
* HTML themes can set up default sidebars through ``theme.conf``
|
||||||
|
|
||||||
|
|
||||||
Features removed
|
Features removed
|
||||||
|
@ -820,8 +820,9 @@ that use Sphinx's HTMLWriter class.
|
|||||||
to include. If all or some of the default sidebars are to be included,
|
to include. If all or some of the default sidebars are to be included,
|
||||||
they must be put into this list as well.
|
they must be put into this list as well.
|
||||||
|
|
||||||
The default sidebars (for documents that don't match any pattern) are:
|
The default sidebars (for documents that don't match any pattern) are
|
||||||
``['localtoc.html', 'relations.html', 'sourcelink.html',
|
defined by theme itself. Builtin themes are using these templates by
|
||||||
|
default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
|
||||||
'searchbox.html']``.
|
'searchbox.html']``.
|
||||||
|
|
||||||
* If a value is a single string, it specifies a custom sidebar to be added
|
* If a value is a single string, it specifies a custom sidebar to be added
|
||||||
|
@ -276,6 +276,7 @@ Python :mod:`ConfigParser` module) and has the following structure:
|
|||||||
inherit = base theme
|
inherit = base theme
|
||||||
stylesheet = main CSS name
|
stylesheet = main CSS name
|
||||||
pygments_style = stylename
|
pygments_style = stylename
|
||||||
|
sidebars = localtoc.html, relations.html, sourcelink.html, searchbox.html
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
variable = default value
|
variable = default value
|
||||||
@ -295,10 +296,16 @@ Python :mod:`ConfigParser` module) and has the following structure:
|
|||||||
highlighting. This can be overridden by the user in the
|
highlighting. This can be overridden by the user in the
|
||||||
:confval:`pygments_style` config value.
|
:confval:`pygments_style` config value.
|
||||||
|
|
||||||
|
* The **sidebars** setting gives the comma separated list of sidebar templates
|
||||||
|
for constructing sidebars. This can be overridden by the user in the
|
||||||
|
:confval:`html_sidebars` config value.
|
||||||
|
|
||||||
* The **options** section contains pairs of variable names and default values.
|
* The **options** section contains pairs of variable names and default values.
|
||||||
These options can be overridden by the user in :confval:`html_theme_options`
|
These options can be overridden by the user in :confval:`html_theme_options`
|
||||||
and are accessible from all templates as ``theme_<name>``.
|
and are accessible from all templates as ``theme_<name>``.
|
||||||
|
|
||||||
|
.. versionadded:: 1.7
|
||||||
|
sidebar settings
|
||||||
|
|
||||||
.. _distribute-your-theme:
|
.. _distribute-your-theme:
|
||||||
|
|
||||||
|
@ -864,9 +864,21 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
def has_wildcard(pattern):
|
def has_wildcard(pattern):
|
||||||
# type: (unicode) -> bool
|
# type: (unicode) -> bool
|
||||||
return any(char in pattern for char in '*?[')
|
return any(char in pattern for char in '*?[')
|
||||||
sidebars = None
|
sidebars = self.theme.get_config('theme', 'sidebars', None)
|
||||||
matched = None
|
matched = None
|
||||||
customsidebar = None
|
customsidebar = None
|
||||||
|
|
||||||
|
# default sidebars settings for selected theme
|
||||||
|
theme_default_sidebars = self.theme.get_config('theme', 'sidebars', None)
|
||||||
|
if theme_default_sidebars:
|
||||||
|
sidebars = [name.strip() for name in theme_default_sidebars.split(',')]
|
||||||
|
elif self.theme.name == 'alabaster':
|
||||||
|
# provide default settings for alabaster (for compatibility)
|
||||||
|
# Note: this will be removed before Sphinx-2.0
|
||||||
|
sidebars = ['about.html', 'navigation.html', 'relation.html',
|
||||||
|
'searchbox.html', 'donate.html']
|
||||||
|
|
||||||
|
# user sidebar settings
|
||||||
for pattern, patsidebars in iteritems(self.config.html_sidebars):
|
for pattern, patsidebars in iteritems(self.config.html_sidebars):
|
||||||
if patmatch(pagename, pattern):
|
if patmatch(pagename, pattern):
|
||||||
if matched:
|
if matched:
|
||||||
@ -881,6 +893,7 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
continue
|
continue
|
||||||
matched = pattern
|
matched = pattern
|
||||||
sidebars = patsidebars
|
sidebars = patsidebars
|
||||||
|
|
||||||
if sidebars is None:
|
if sidebars is None:
|
||||||
# keep defaults
|
# keep defaults
|
||||||
pass
|
pass
|
||||||
|
@ -110,14 +110,12 @@ html_static_path = ['{{ dot }}static']
|
|||||||
# Custom sidebar templates, must be a dictionary that maps document names
|
# Custom sidebar templates, must be a dictionary that maps document names
|
||||||
# to template names.
|
# to template names.
|
||||||
#
|
#
|
||||||
# This is required for the alabaster theme
|
# The default sidebars (for documents that don't match any pattern) are
|
||||||
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
|
# defined by theme itself. Builtin themes are using these templates by
|
||||||
html_sidebars = {
|
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
|
||||||
'**': [
|
# 'searchbox.html']``.
|
||||||
'relations.html', # needs 'show_related': True theme option to display
|
#
|
||||||
'searchbox.html',
|
# html_sidebars = {}
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# -- Options for HTMLHelp output ------------------------------------------
|
# -- Options for HTMLHelp output ------------------------------------------
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
inherit = none
|
inherit = none
|
||||||
stylesheet = basic.css
|
stylesheet = basic.css
|
||||||
pygments_style = none
|
pygments_style = none
|
||||||
|
sidebars = localtoc.html, relations.html, sourcelink.html, searchbox.html
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
nosidebar = false
|
nosidebar = false
|
||||||
|
@ -12,6 +12,9 @@ Sphinx uses reStructuredText as its markup language, and many of its strengths
|
|||||||
come from the power and straightforwardness of reStructuredText and its parsing
|
come from the power and straightforwardness of reStructuredText and its parsing
|
||||||
and translating suite, the Docutils.
|
and translating suite, the Docutils.
|
||||||
|
|
||||||
|
features
|
||||||
|
--------
|
||||||
|
|
||||||
Among its features are the following:
|
Among its features are the following:
|
||||||
|
|
||||||
* Output formats: HTML (including derivative formats such as HTML Help, Epub
|
* Output formats: HTML (including derivative formats such as HTML Help, Epub
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
[theme]
|
[theme]
|
||||||
inherit = classic
|
inherit = classic
|
||||||
|
sidebars = globaltoc.html, searchbox.html
|
||||||
|
@ -1245,3 +1245,21 @@ def test_html_remote_images(app, status, warning):
|
|||||||
assert ('<img alt="https://www.python.org/static/img/python-logo.png" '
|
assert ('<img alt="https://www.python.org/static/img/python-logo.png" '
|
||||||
'src="https://www.python.org/static/img/python-logo.png" />' in result)
|
'src="https://www.python.org/static/img/python-logo.png" />' in result)
|
||||||
assert not (app.outdir / 'python-logo.png').exists()
|
assert not (app.outdir / 'python-logo.png').exists()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('html', testroot='basic')
|
||||||
|
def test_html_sidebar(app, status, warning):
|
||||||
|
app.builder.build_all()
|
||||||
|
result = (app.outdir / 'index.html').text(encoding='utf8')
|
||||||
|
assert '<h3><a href="#">Table Of Contents</a></h3>' in result
|
||||||
|
assert '<h3>Related Topics</h3>' in result
|
||||||
|
assert '<h3>This Page</h3>' in result
|
||||||
|
assert '<h3>Quick search</h3>' in result
|
||||||
|
|
||||||
|
app.config.html_sidebars = {'**': []}
|
||||||
|
app.builder.build_all()
|
||||||
|
result = (app.outdir / 'index.html').text(encoding='utf8')
|
||||||
|
assert '<h3><a href="#">Table Of Contents</a></h3>' not in result
|
||||||
|
assert '<h3>Related Topics</h3>' not in result
|
||||||
|
assert '<h3>This Page</h3>' not in result
|
||||||
|
assert '<h3>Quick search</h3>' not in result
|
||||||
|
@ -95,3 +95,15 @@ def test_double_inheriting_theme(app, status, warning):
|
|||||||
def test_nested_zipped_theme(app, status, warning):
|
def test_nested_zipped_theme(app, status, warning):
|
||||||
assert app.builder.theme.name == 'child'
|
assert app.builder.theme.name == 'child'
|
||||||
app.build() # => not raises TemplateNotFound
|
app.build() # => not raises TemplateNotFound
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx(testroot='theming')
|
||||||
|
def test_theme_sidebars(app, status, warning):
|
||||||
|
app.build()
|
||||||
|
|
||||||
|
# test-theme specifies globaltoc and searchbox as default sidebars
|
||||||
|
result = (app.outdir / 'index.html').text(encoding='utf8')
|
||||||
|
assert '<h3><a href="#">Table Of Contents</a></h3>' in result
|
||||||
|
assert '<h3>Related Topics</h3>' not in result
|
||||||
|
assert '<h3>This Page</h3>' not in result
|
||||||
|
assert '<h3>Quick search</h3>' in result
|
||||||
|
Loading…
Reference in New Issue
Block a user