learning-website-framework1-2 Exercise 1: A Coverage Checker for the Site Map ============================================================================= Save as check_sites.py and run (pass the path to your content/ folder): python check_sites.py "C:/path/to/website-content/content" import os, sys from collections import Counter CONTENT = sys.argv[1] SITES = { "languages": ["france", "germany", "hungary", "japan", "culture"], "webdevelopment": ["web-development", "web-platforms", "web-servers"], "programming": ["programming", "software-development", "maths-for-programmers", "retro-computing", "game-development", "android-development", "ios-development", "databases", "blockchain-and-web3", "developer-tools", "projects"], "systems": ["linux", "operating-systems", "networking", "cloud-and-devops", "security", "technical-support", "raspberry-pi", "windows"], "ai": ["ai", "data-science-and-ml"], "humanities": ["history", "politics", "philosophy", "art-history", "classic-literature", "science-fiction", "sci-fi-project", "music", "football", "ethics", "study-methodologies", "science"], "lifeskills": ["practical-life-skills", "cookery", "freelancing-and-business-skills", "youtube"], "creative": ["creative-and-design-tools", "audio-video-production", "office-and-productivity-software"], } SIDEBAR_ROUTES = { "ai": "ai", "drinks": "lifeskills", "football": "humanities", "history": "humanities", "linux": "systems", "programming": "programming", "web-development": "webdevelopment", } folder_to_site = {} problems = [] for site, folders in SITES.items(): for f in folders: if f in folder_to_site: problems.append(f"DUPLICATE: {f} is in {folder_to_site[f]} and {site}") folder_to_site[f] = site on_disk = sorted(d for d in os.listdir(CONTENT) if os.path.isdir(os.path.join(CONTENT, d)) and d != "sidebar") for d in on_disk: if d not in folder_to_site: problems.append(f"UNASSIGNED: {d}") for f in folder_to_site: if f not in on_disk: problems.append(f"MISSING ON DISK: {f}") sidebar_dir = os.path.join(CONTENT, "sidebar") for d in sorted(os.listdir(sidebar_dir)): if os.path.isdir(os.path.join(sidebar_dir, d)) and d not in SIDEBAR_ROUTES: problems.append(f"SIDEBAR UNROUTED: sidebar/{d}") print(f"Top-level folders on disk (excluding sidebar): {len(on_disk)}") counts = Counter(folder_to_site[d] for d in on_disk if d in folder_to_site) for site, n in sorted(counts.items(), key=lambda kv: -kv[1]): print(f" {site:<16} {n:>3} folders") print() print("Problems:" if problems else "No problems: every folder has exactly one home.") for p in problems: print(" " + p) Output on this site's content/ folder (checked by running it): Top-level folders on disk (excluding sidebar): 48 humanities 12 folders programming 11 folders systems 8 folders languages 5 folders lifeskills 4 folders creative 3 folders webdevelopment 3 folders ai 2 folders No problems: every folder has exactly one home. To see the checker catch something, remove "ethics" from the humanities list and run it again. You should see: UNASSIGNED: ethics WHY THIS WORKS AS AN ANSWER --------------------------- The map is only useful if it is complete and unambiguous: every folder must have exactly one home. The script turns that rule into something a computer checks, so the rule keeps holding when new top-level folders are added later. Counting folders is a crude size measure (languages has few folders but many chapters), so combine this with the page counts from Exercise 1 of Learning Website: Framework & Architecture 1 when judging how balanced the sites are.