From cc552c079c824bce9ebf84adb959f2083fff7e84 Mon Sep 17 00:00:00 2001 From: Chris Holdgraf Date: Thu, 10 Sep 2020 18:44:03 -0700 Subject: [PATCH 1/5] adding sphinx sidebars functionality --- docs/_templates/custom-template.html | 6 +++ docs/conf.py | 3 ++ docs/user_guide/configuring.rst | 11 ++++++ pydata_sphinx_theme/__init__.py | 5 +++ pydata_sphinx_theme/_templates/nav-bs.html | 32 ++++++++++++++++ pydata_sphinx_theme/_templates/search-bs.html | 3 ++ pydata_sphinx_theme/docs-sidebar.html | 38 ------------------- pydata_sphinx_theme/layout.html | 4 +- pydata_sphinx_theme/theme.conf | 1 + tests/sites/base/conf.py | 2 + tests/test_build/sidebar_subpage.html | 5 --- 11 files changed, 66 insertions(+), 44 deletions(-) create mode 100644 docs/_templates/custom-template.html create mode 100644 pydata_sphinx_theme/_templates/nav-bs.html create mode 100644 pydata_sphinx_theme/_templates/search-bs.html diff --git a/docs/_templates/custom-template.html b/docs/_templates/custom-template.html new file mode 100644 index 000000000..aaf11cec2 --- /dev/null +++ b/docs/_templates/custom-template.html @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 99d135133..6ad7b292c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -49,6 +49,9 @@ # This pattern also affects html_static_path and html_extra_path. exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] +html_sidebars = { + "contributing": ["search-bs.html", "custom-template.html"], +} # -- Options for HTML output ------------------------------------------------- diff --git a/docs/user_guide/configuring.rst b/docs/user_guide/configuring.rst index d223872b8..9945c1a39 100644 --- a/docs/user_guide/configuring.rst +++ b/docs/user_guide/configuring.rst @@ -48,6 +48,17 @@ an external site. You can add external links to the nav bar like so: ] } +Configure the sidebar +===================== + +``pydata_sphinx_theme`` provides two new sidebar items by default: + +- ``nav-bs.html`` - a bootstrap-friendly navigation section +- ``search-bs.html`` - a bootstrap-friendly search bar + +By default, this theme's sidebar has these two elements in it. If you'd like to +override this behavior and control the sidebar on a per-page basis, use the +`Sphinx html-sidebars configuration value `_. Hiding the previous and next buttons ==================================== diff --git a/pydata_sphinx_theme/__init__.py b/pydata_sphinx_theme/__init__.py index e7829a5e0..6b33847e5 100644 --- a/pydata_sphinx_theme/__init__.py +++ b/pydata_sphinx_theme/__init__.py @@ -196,4 +196,9 @@ def setup(app): app.connect("html-page-context", setup_edit_url) app.connect("html-page-context", add_toctree_functions) + # Update templates for sidebar + pkgdir = os.path.abspath(os.path.dirname(__file__)) + path_templates = os.path.join(pkgdir, "_templates") + app.config.templates_path.append(path_templates) + return {"parallel_read_safe": True, "parallel_write_safe": True} diff --git a/pydata_sphinx_theme/_templates/nav-bs.html b/pydata_sphinx_theme/_templates/nav-bs.html new file mode 100644 index 000000000..b3713ad52 --- /dev/null +++ b/pydata_sphinx_theme/_templates/nav-bs.html @@ -0,0 +1,32 @@ + diff --git a/pydata_sphinx_theme/_templates/search-bs.html b/pydata_sphinx_theme/_templates/search-bs.html new file mode 100644 index 000000000..3ccb6fbaa --- /dev/null +++ b/pydata_sphinx_theme/_templates/search-bs.html @@ -0,0 +1,3 @@ +{% if theme_search_bar_position == "sidebar" %} + {%- include "search-field.html" %} +{% endif %} \ No newline at end of file diff --git a/pydata_sphinx_theme/docs-sidebar.html b/pydata_sphinx_theme/docs-sidebar.html index 1578f7395..e69de29bb 100644 --- a/pydata_sphinx_theme/docs-sidebar.html +++ b/pydata_sphinx_theme/docs-sidebar.html @@ -1,38 +0,0 @@ - - -{% if theme_search_bar_position == "sidebar" %} - {%- include "search-field.html" %} -{% endif %} - - diff --git a/pydata_sphinx_theme/layout.html b/pydata_sphinx_theme/layout.html index e9bebd678..e7fc38ebd 100644 --- a/pydata_sphinx_theme/layout.html +++ b/pydata_sphinx_theme/layout.html @@ -46,7 +46,9 @@
{% block docs_sidebar %}
- {%- include "docs-sidebar.html" %} + {%- for sidebartemplate in sidebars %} + {%- include sidebartemplate %} + {%- endfor %}
{% endblock %} diff --git a/pydata_sphinx_theme/theme.conf b/pydata_sphinx_theme/theme.conf index 862752282..982f1a629 100644 --- a/pydata_sphinx_theme/theme.conf +++ b/pydata_sphinx_theme/theme.conf @@ -1,6 +1,7 @@ [theme] inherit = basic pygments_style = tango +sidebars = search-bs.html, nav-bs.html [options] sidebarwidth = 270 diff --git a/tests/sites/base/conf.py b/tests/sites/base/conf.py index 22ae567c7..1dac35a0d 100644 --- a/tests/sites/base/conf.py +++ b/tests/sites/base/conf.py @@ -18,3 +18,5 @@ # Base options, we can add other key/vals later html_theme_options = {} + +html_sidebars = {"section1/index": ["nav-bs.html"]} diff --git a/tests/test_build/sidebar_subpage.html b/tests/test_build/sidebar_subpage.html index 82e0378fb..629909d54 100644 --- a/tests/test_build/sidebar_subpage.html +++ b/tests/test_build/sidebar_subpage.html @@ -1,9 +1,4 @@
-