import os

def on_page_markdown(markdown, page, config, files):
    """
    Hook to override page title with its filename (sanitized) to keep sidebar clean.
    """
    # Get filename without extension
    filename = os.path.basename(page.file.src_path)
    filename_no_ext = os.path.splitext(filename)[0]
    
    # Replace underscores/dashes with spaces for readability in sidebar
    clean_title = filename_no_ext.replace('_', ' ').replace('-', ' ')
    
    # Override the title used in navigation
    page.title = clean_title
    
    return markdown
