CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pydata-sphinx-theme

Bootstrap-based Sphinx theme from the PyData community

Pending
Overview
Eval results
Files

theme-setup.mddocs/

Theme Setup and Configuration

Core functionality for registering the PyData Sphinx Theme with Sphinx and managing configuration options, including theme options validation, deprecated key handling, and analytics integration.

Capabilities

Theme Registration

Registers the theme with Sphinx's extension system and sets up all event handlers and configuration.

def setup(app: Sphinx) -> Dict[str, str]:
    """
    Setup the Sphinx application.
    
    This is the main entry point that:
    - Registers the HTML theme with Sphinx
    - Adds post-transforms for link processing
    - Connects event handlers for configuration and template processing
    - Sets up message catalogs for internationalization
    - Configures template paths
    
    Parameters:
    - app (Sphinx): The Sphinx application instance
    
    Returns:
    Dict[str, str]: Extension metadata with parallel read/write safety flags
    """

Configuration Management

Updates and validates theme configuration options, handling deprecated keys and setting defaults.

def update_config(app):
    """
    Update config with new default values and handle deprecated keys.
    
    This function:
    - Handles deprecated pygments style key names
    - Validates icon_links configuration format
    - Sets default permalink icons if not provided by user
    - Validates and processes theme switcher configuration
    - Adds analytics scripts (Google Analytics and Plausible)
    - Configures ABlog integration if present
    - Processes icon link shortcuts for common platforms
    - Prepares logo configuration dictionary
    
    Parameters:
    - app: Sphinx application instance with theme options
    
    Raises:
    - ExtensionError: If icon_links is not a list or logo config is invalid
    """

Usage Examples

Basic Theme Registration

# This happens automatically when Sphinx loads the theme
html_theme = "pydata_sphinx_theme"

Advanced Configuration

# conf.py
html_theme = "pydata_sphinx_theme"
html_theme_options = {
    # Logo configuration
    "logo": {
        "image_light": "logo-light.png",
        "image_dark": "logo-dark.png", 
        "text": "My Project",
        "link": "https://myproject.org"
    },
    
    # Icon links in header
    "icon_links": [
        {
            "name": "GitHub",
            "url": "https://github.com/user/repo",
            "icon": "fa-brands fa-square-github",
            "type": "fontawesome",
        },
        {
            "name": "PyPI",
            "url": "https://pypi.org/project/mypackage/",
            "icon": "fa-custom fa-pypi",
            "type": "fontawesome",
        }
    ],
    
    # Analytics integration
    "analytics": {
        "google_analytics_id": "G-XXXXXXXXXX",
        "plausible_analytics_domain": "mysite.com",
        "plausible_analytics_url": "https://plausible.io/js/script.js"
    },
    
    # Theme switcher
    "switcher": {
        "json_url": "https://mysite.com/switcher.json",
        "version_match": "0.1.0"
    },
    
    # Pygments styling
    "pygments_light_style": "github-light",
    "pygments_dark_style": "github-dark",
    
    # Navigation
    "show_toc_level": 2,
    "navbar_align": "left",
    "show_nav_level": 1,
    
    # Footer
    "footer_start": ["copyright"],
    "footer_center": ["sphinx-version"],
    "footer_end": ["theme-version"]
}

# Deprecated shortcuts (still supported)
html_theme_options = {
    "github_url": "https://github.com/user/repo",  # Converted to icon_links
    "twitter_url": "https://twitter.com/user",    # Converted to icon_links
}

Icon Links Configuration

# Icon links support multiple types and configurations
html_theme_options = {
    "icon_links": [
        # FontAwesome icons
        {
            "name": "GitHub",
            "url": "https://github.com/user/repo", 
            "icon": "fa-brands fa-github",
            "type": "fontawesome"
        },
        
        # Local image icons
        {
            "name": "Custom Service",
            "url": "https://service.com",
            "icon": "_static/service-icon.png", 
            "type": "local"
        },
        
        # URL-based icons
        {
            "name": "External Service",
            "url": "https://external.com",
            "icon": "https://external.com/icon.png",
            "type": "url"
        }
    ]
}

Analytics Configuration

# Google Analytics setup
html_theme_options = {
    "analytics": {
        "google_analytics_id": "G-XXXXXXXXXX"
    }
}

# Plausible Analytics setup  
html_theme_options = {
    "analytics": {
        "plausible_analytics_domain": "mysite.com",
        "plausible_analytics_url": "https://plausible.io/js/script.js"
    }
}

# Both analytics services
html_theme_options = {
    "analytics": {
        "google_analytics_id": "G-XXXXXXXXXX",
        "plausible_analytics_domain": "mysite.com", 
        "plausible_analytics_url": "https://plausible.io/js/script.js"
    }
}

Configuration Validation

The theme validates several configuration options:

  • icon_links: Must be a list of dictionaries
  • logo: Must be a dictionary if provided
  • switcher: Must contain json_url and version_match keys if provided
  • analytics: Validates analytics service configurations

Invalid configurations will raise ExtensionError exceptions during Sphinx initialization.

Install with Tessl CLI

npx tessl i tessl/pypi-pydata-sphinx-theme

docs

edit-page.md

html-translation.md

index.md

link-processing.md

logo-management.md

syntax-highlighting.md

template-management.md

theme-setup.md

toc-processing.md

utilities.md

tile.json