Created
December 23, 2025 19:24
-
-
Save kornysietsma/e8b38037f05d49333bd6439dfaf3e392 to your computer and use it in GitHub Desktop.
Claude generated script to sort a markdown file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env -S uv run --script | |
| # /// script | |
| # dependencies = [] | |
| # requires-python = ">=3.12" | |
| # /// | |
| import re | |
| from pathlib import Path | |
| def main(): | |
| file_path = Path("_pages/video-games.md") | |
| content = file_path.read_text() | |
| # Split at "## Games" to separate header from game sections | |
| parts = content.split("## Games\n", 1) | |
| if len(parts) != 2: | |
| print("Could not find '## Games' section") | |
| return | |
| header = parts[0] + "## Games\n" | |
| games_content = parts[1] | |
| # Split into individual game sections (### Game Name ... ---) | |
| # Each game section starts with ### and ends with --- (or end of file) | |
| game_pattern = r"(### .+?)(?=### |\*Page last updated|\Z)" | |
| games = re.findall(game_pattern, games_content, re.DOTALL) | |
| # Extract game name and content for sorting | |
| game_entries = [] | |
| for game in games: | |
| match = re.match(r"### (.+?)\n", game) | |
| if match: | |
| name = match.group(1).strip() | |
| # Sort key: lowercase, ignore "The " prefix | |
| sort_key = name.lower() | |
| if sort_key.startswith("the "): | |
| sort_key = sort_key[4:] | |
| game_entries.append((sort_key, name, game.strip())) | |
| # Sort alphabetically | |
| game_entries.sort(key=lambda x: x[0]) | |
| # Rebuild the file | |
| sorted_games = "\n\n---\n\n".join(entry[2].rstrip("-\n ") for entry in game_entries) | |
| # Find the footer (Page last updated line) | |
| footer_match = re.search(r"(\*Page last updated:.+)$", games_content, re.DOTALL) | |
| footer = footer_match.group(1) if footer_match else "" | |
| result = header + "\n" + sorted_games + "\n\n---\n\n" + footer | |
| file_path.write_text(result) | |
| print(f"Sorted {len(game_entries)} games:") | |
| for _, name, _ in game_entries: | |
| print(f" - {name}") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment