Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing sidebar #124

Merged
merged 3 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion docs/customizing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ relevant rules:
/* Import from Google Fonts, a CDN, or files in your _static folder.
This Google Fonts import provides its own `@font-face` CSS;
if providing your own font files, you'll also need to
provide your own @font-face` code. */
provide your own `@font-face` code. */
@import url("https://fonts.googleapis.com/css2?family=Roboto");

/* Main font used throughout the docs. */
Expand All @@ -117,3 +117,35 @@ relevant rules:
pre, code, kbd, samp {
font-family: "Courier New", monospace;
}

Customize the Sidebar
---------------------

To change the contents of the sidebar, create a custom HTML template and specify
it in ``conf.py``. For example, let's add a link to sponsor your project below
the table of contents tree:

.. code-block:: python

# Add any relative paths that contain templates.
templates_path = ["_templates"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names. "**" will apply the templates to all pages.
# The theme default is just searchbox and globaltoc.
html_sidebars = {"**": [
"searchbox.html",
"globaltoc.html",
"custom.html", # Your template here
]}

Then in ``_templates/custom.html``:

.. code-block:: html

<p>
Sponsor my project!
<a href="http://example.com">Here's the link</a>
</p>

Read more about `customizing the sidebar in Sphinx <https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_sidebars>`_
5 changes: 5 additions & 0 deletions sphinx_wagtail_theme/globaltoc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="site-toc">
<nav class="toc mt-3" aria-label="Main menu">
{{ toctree(includehidden=False, collapse=False, maxdepth=8, titles_only=True) }}
</nav>
</div>
14 changes: 3 additions & 11 deletions sphinx_wagtail_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,9 @@
<div class="row">
<aside class="col-12 col-lg-3">
<div id="collapseSidebar" class="collapse sticky-top d-lg-block pt-5">
{%- if not theme_is_homepage and builder == 'html' %}
{%- include "searchbox.html" %}
{%- endif %}
<div class="site-toc">
<nav class="toc mt-3" aria-label="Main menu">
{%- set toctree = toctree(maxdepth=8, collapse=False, includehidden=False, titles_only=True) -%}
{%- if toctree %}
{{ toctree }}
{%- endif %}
</nav>
</div>
{%- for sidebartemplate in sidebars %}
{%- include sidebartemplate %}
{%- endfor %}
<div class="d-lg-none border-bottom">
{# Bottom border for mobile (above content, needs to be expanded.) #}
</div>
Expand Down
2 changes: 1 addition & 1 deletion sphinx_wagtail_theme/theme.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[theme]
inherit = none
sidebars = searchbox.html, globaltoc.html
stylesheet = dist/theme.css
pygments_style = none

[options]
is_homepage =
project_name = Sphinx Wagtail Theme
logo = img/wagtail-logo-new.svg
logo_alt = Wagtail
Expand Down