Skip to content
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
2 changes: 1 addition & 1 deletion docs/source/_templates/versioning.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<label class="version-switcher">
<span class="version-switcher__label">Version</span>
<select class="version-switcher__select" onchange="location = this.value;">
{%- for item in versions.branches %}
{%- for item in sort_doc_branches(versions.branches) %}
<option value="{{ item.url }}" {% if item == current_version %}selected{% endif %}>{{ item.name }}</option>
{%- endfor %}
{%- for item in versions.tags|reverse %}
Expand Down
19 changes: 19 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import re
import sys
from datetime import datetime, timezone

Expand Down Expand Up @@ -176,6 +177,23 @@ def _pip_pin(ref_name, fallback):
"**": ["icon-links", "sidebar-nav-bs"],
}


def _sort_doc_branches(branches):
return sorted(
branches,
key=lambda item: (
item.name != "main",
tuple(map(int, re.findall(r"\d+", item.name))),
item.name,
),
)


def _versioning_context(app, pagename, templatename, context, doctree):
# Callables belong in page context; html_context must remain pickleable.
context["sort_doc_branches"] = _sort_doc_branches


# Edit page button: link to GitHub so users can suggest edits (PyData theme uses html_context)
html_context = {
"github_user": "NVIDIA",
Expand Down Expand Up @@ -232,6 +250,7 @@ def _external_links_new_tab(app, doctree, docname):


def setup(app):
app.connect("html-page-context", _versioning_context)
app.add_role("code-file", _code_file_role)
app.add_role("code-dir", _code_dir_role)
app.add_config_value("html_external_links_new_tab", True, "html")
Expand Down
Loading