{# Version Selector Component Displays a dropdown to switch between documentation versions. Only renders when versioning is enabled. Available context: - versioning_enabled: bool - Whether versioning is enabled - versions: list[dict] - All versions with id, label, latest, url_prefix - current_version: dict|None - Current page's version info - is_latest_version: bool - Whether current page is latest version Usage in templates: {% include "partials/version-selector.html" %} Customization: Override this partial in your theme to customize the version selector. You can also style it using CSS class: .version-selector Engine-Agnostic: Uses site.get_version_target_url() method which works with any template engine (Jinja2, Mako, or BYORenderer). No global function dependency. #} {# Only show version selector if: 1. Versioning is enabled 2. There are multiple versions 3. The current page is actually versioned (has a version attribute) 4. The page is not an autodoc page (autodoc pages are not versioned) #} {% set is_autodoc = is_autodoc_page(page) if is_autodoc_page else false, page_is_versioned = page.version is not none %} {% if versioning_enabled and versions | length > 1 and page_is_versioned and not is_autodoc %}
{# Smart Version Selector with Pre-computed Fallback URLs Each option has a data-target attribute containing the best URL to navigate to in that version. This is computed at build time, so switching versions is instant with no 404 errors. Fallback cascade (computed at build time): 1. Exact equivalent page exists → use it 2. Section index exists → use section index 3. Version root → use version root This approach is better than any major static SSG (Docusaurus, MkDocs, etc.) which all show 404 errors when switching versions. #}
{# Styles: assets/css/components/versioning.css #} {# Script: assets/js/core/version-selector.js #} {% end %}