Added comments and cleaned up python source code

This commit is contained in:
Lucas
2026-01-12 11:35:59 -08:00
parent e3868dbdad
commit 119f95a492
5 changed files with 17 additions and 19 deletions

View File

@@ -1,8 +1,7 @@
from tableofcontents_generator import generate_table_of_contents
from contents_generator import generate_contents
from mainheader_generator import generate_mainheader
from tableofcontents_generator import generate_table_of_contents
# List of target platforms
platforms = ["all", "windows", "macos", "linux", "selfhost"]
# Platforms mapped to corresponding header files
@@ -19,27 +18,22 @@ def generate_readme_for_platform(platform):
content = ""
header_file = header_files.get(platform, "core/components/header.md")
# Inject mainheader with dynamic project count
# Inject every component of the list from top to bottom
if platform == "all":
content += generate_mainheader()
# Inject header
with open(header_file, "r", encoding="utf-8") as f:
content += f.read() + "\n"
# Inject tags.md
with open("core/components/tags.md", "r", encoding="utf-8") as f:
content += f.read() + "\n"
# Generate Table of Contents
toc_md = generate_table_of_contents()
content += toc_md + "\n"
# Generate the actual markdown list of contents for the given platform
contents_md = generate_contents(platform)
content += contents_md + "\n"
# Inject footer.md
with open("core/components/footer.md", "r", encoding="utf-8") as f:
content += f.read() + "\n"

View File

@@ -1,13 +1,12 @@
import json
# Utils
def slugify(name):
# 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", [])
@@ -21,17 +20,16 @@ def generate_table_of_contents():
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}
# Group subcategories by their parent id
grouped = {}
for sub in subcategories:
parent = sub.get("parent", "other")
grouped.setdefault(parent, []).append(sub["name"])
# Sort each group's subcategories alphabetically
for key in grouped:
grouped[key].sort(key=lambda x: x.lower())
# Sort parent categories (exclude "other", which is appended at the end)
parents = [(pid, parent_map.get(pid, "Other")) for pid in grouped if pid != "other"]
parents.sort(key=lambda x: x[1].lower())
if "other" in grouped:
@@ -64,7 +62,7 @@ def generate_table_of_contents():
<details open>
<summary><b>Categorized</b></summary> <br />
{categorized_md}
</details>
"""