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

Add option to collapse navbar #748

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/customisation/index.md
Expand Up @@ -50,6 +50,18 @@ html_theme_options = {
Typos in the `*_css_variables` dictionary are silently ignored, and do not raise any errors or warnings. Double check that your spellings and values are correct and valid.
```

(collapse_navbar)=

### `collapse_navbar`

Whether to collapse the navbar, stopping the tree from being expanded. (False is default)

```python
html_theme_options = {
"collapse_navbar": True,
}
```

(sidebar_hide_name)=

### `sidebar_hide_name`
Expand Down
19 changes: 2 additions & 17 deletions src/furo/__init__.py
Expand Up @@ -114,22 +114,6 @@ def get_colors_for_codeblocks(
)


def _compute_navigation_tree(context: Dict[str, Any]) -> str:
# The navigation tree, generated from the sphinx-provided ToC tree.
if "toctree" in context:
toctree = context["toctree"]
toctree_html = toctree(
collapse=False,
titles_only=True,
maxdepth=-1,
includehidden=True,
)
else:
toctree_html = ""

return get_navigation_tree(toctree_html)


def _compute_hide_toc(
context: Dict[str, Any],
*,
Expand Down Expand Up @@ -224,7 +208,8 @@ def _html_page_context(
context["furo_version"] = __version__

# Values computed from page-level context.
context["furo_navigation_tree"] = _compute_navigation_tree(context)
context["toctree"] = context.get("toctree", None)
context["get_navigation_tree"] = get_navigation_tree
context["furo_hide_toc"] = _compute_hide_toc(
context, builder=cast(StandaloneHTMLBuilder, app.builder), docname=pagename
)
Expand Down
7 changes: 6 additions & 1 deletion src/furo/theme/furo/sidebar/navigation.html
@@ -1,3 +1,8 @@
<div class="sidebar-tree">
{{ furo_navigation_tree }}
{% if toctree is defined %}
{% set toctree_html = toctree(collapse=theme_collapse_navbar, titles_only=True, maxdepth=-1, includehidden=True) %}
{% else %}
{% set toctree_html = "" %}
{% endif %}
{{ get_navigation_tree(toctree_html) }}
</div>
1 change: 1 addition & 0 deletions src/furo/theme/furo/theme.conf
Expand Up @@ -15,6 +15,7 @@ sidebars =

[options]
announcement =
collapse_navbar = False
dark_css_variables =
dark_logo =
light_css_variables =
Expand Down