Ran ruff format

This commit is contained in:
Lucas
2026-01-12 10:08:49 -08:00
parent d04d9bf430
commit 84bab5f5d5
6 changed files with 113 additions and 80 deletions

View File

@@ -1,23 +1,25 @@
import json
def slugify(name):
#Create an anchor-friendly slug from a string
# Create an anchor-friendly slug from a string
return name.lower().replace(" ", "-").replace("(", "").replace(")", "")
def generate_table_of_contents():
# Load the categories JSON data
with open("core/data/static/categories.json", "r", encoding="utf-8") as f:
data = json.load(f)
categories = data.get("categories", [])
subcategories = data.get("subcategories", [])
# Build the alphabetical list (ignoring parent categories)
subcat_names = [sub["name"] for sub in subcategories]
subcat_names.sort(key=lambda x: x.lower())
alphabetical_md = ""
for name in subcat_names:
alphabetical_md += f"- [{name}](#{slugify(name)})\n"
# Build the categorized list
# Create a mapping from parent id to parent name
parent_map = {cat["id"]: cat["name"] for cat in categories}
@@ -34,20 +36,24 @@ def generate_table_of_contents():
parents.sort(key=lambda x: x[1].lower())
if "other" in grouped:
parents.append(("other", "Other"))
categorized_md_lines = []
for pid, pname in parents:
categorized_md_lines.append(f"- {pname}")
for subname in grouped[pid]:
categorized_md_lines.append(f" - [{subname}](#{slugify(subname)})")
# Append fixed sections at the end of the categorized TOC
fixed_sections = ["Removed Projects", "FAQ", "Honorable Mentions of Closed-Source Software"]
fixed_sections = [
"Removed Projects",
"FAQ",
"Honorable Mentions of Closed-Source Software",
]
for item in fixed_sections:
categorized_md_lines.append(f"- [{item}](#{slugify(item)})")
categorized_md = "\n".join(categorized_md_lines)
toc = f"""## Table of Contents
<details>
@@ -64,6 +70,7 @@ def generate_table_of_contents():
"""
return toc
if __name__ == "__main__":
# For testing the TOC generator
print(generate_table_of_contents())