mirror of
https://github.com/mustbeperfect/definitive-opensource.git
synced 2026-04-17 23:53:26 +02:00
Renamed generators to generation and added to ARCHITECTURE.md
This commit is contained in:
120
source/scripts/generation/contents_generator.py
Normal file
120
source/scripts/generation/contents_generator.py
Normal file
@@ -0,0 +1,120 @@
|
||||
import json
|
||||
|
||||
def slugify(name):
|
||||
|
||||
return name.lower().replace(" ", "-").replace("(", "").replace(")", "")
|
||||
|
||||
def extract_repo_path(link):
|
||||
|
||||
parts = link.rstrip("/").split("/")
|
||||
if len(parts) >= 5:
|
||||
return f"{parts[-2]}/{parts[-1]}"
|
||||
return ""
|
||||
|
||||
def format_stars(n):
|
||||
if n >= 1_000_000:
|
||||
return f"{n/1_000_000:.1f}M"
|
||||
elif n >= 1_000:
|
||||
return f"{n/1_000:.1f}k"
|
||||
else:
|
||||
return str(n)
|
||||
|
||||
def generate_contents(platform="all"):
|
||||
|
||||
with open("source/data/categories.json", "r", encoding="utf-8") as f:
|
||||
cat_data = json.load(f)
|
||||
with open("source/data/applications.json", "r", encoding="utf-8") as f:
|
||||
app_data = json.load(f)
|
||||
with open("source/data/tags.json", "r", encoding="utf-8") as f:
|
||||
tags_data = json.load(f)
|
||||
|
||||
categories = cat_data.get("categories", [])
|
||||
subcategories = cat_data.get("subcategories", [])
|
||||
applications = app_data.get("applications", [])
|
||||
|
||||
|
||||
parent_map = {cat["id"]: cat["name"] for cat in categories}
|
||||
|
||||
|
||||
tag_map = {tag["id"]: tag["emoji"] for tag in tags_data["tags"]}
|
||||
|
||||
|
||||
subcat_by_parent = {}
|
||||
for sub in subcategories:
|
||||
parent = sub.get("parent", "other")
|
||||
subcat_by_parent.setdefault(parent, []).append({
|
||||
"Name": sub["name"],
|
||||
"id": sub["id"]
|
||||
})
|
||||
|
||||
for key in subcat_by_parent:
|
||||
subcat_by_parent[key].sort(key=lambda x: x["Name"].lower())
|
||||
|
||||
|
||||
apps_by_subcat = {}
|
||||
for app in applications:
|
||||
include = False
|
||||
if platform == "all":
|
||||
include = True
|
||||
else:
|
||||
|
||||
app_platforms = [p.lower() for p in app.get("platforms", [])]
|
||||
target = platform.lower()
|
||||
if target in app_platforms:
|
||||
include = True
|
||||
|
||||
|
||||
if target in ["macos", "linux", "windows"] and "cross" in app_platforms:
|
||||
include = True
|
||||
if not include:
|
||||
continue
|
||||
|
||||
cat_id = app.get("category", "uncategorized")
|
||||
apps_by_subcat.setdefault(cat_id, []).append(app)
|
||||
|
||||
|
||||
for key in apps_by_subcat:
|
||||
apps_by_subcat[key].sort(key=lambda x: x["name"].lower())
|
||||
|
||||
|
||||
md_output = ""
|
||||
|
||||
parent_items = [(pid, parent_map.get(pid, pid)) for pid in subcat_by_parent if pid != "other"]
|
||||
parent_items.sort(key=lambda x: x[1].lower())
|
||||
if "other" in subcat_by_parent:
|
||||
parent_items.append(("other", "Other"))
|
||||
|
||||
for pid, pname in parent_items:
|
||||
md_output += f"# {pname} - [Go to top](#contents)\n\n"
|
||||
|
||||
for sub in subcat_by_parent.get(pid, []):
|
||||
subname = sub["Name"]
|
||||
md_output += f"### {subname}\n\n"
|
||||
md_output += "| Name | Description | Platform | Stars |\n"
|
||||
md_output += "| --- | --- | --- | --- |\n"
|
||||
|
||||
apps = apps_by_subcat.get(sub["id"], [])
|
||||
for app in apps:
|
||||
name = app.get("name", "")
|
||||
description = app.get("description", "").replace("|", "-")
|
||||
link = app.get("repo_url", "#")
|
||||
tags = ""
|
||||
"""
|
||||
if app.get("tags"):
|
||||
tags += " " + " ".join(app["tags"])
|
||||
"""
|
||||
if app.get("tags"):
|
||||
tags = " " + " ".join(tag_map.get(tag, tag) for tag in app.get("tags", []))
|
||||
|
||||
app_platforms = " ".join(f"`{p}`" for p in app.get("platforms", []))
|
||||
stars = app.get("stars")
|
||||
stars_formatted = f"**{format_stars(stars)}**" if stars is not None else ""
|
||||
# repo_path = extract_repo_path(link)
|
||||
# stars_badge = f"" if repo_path else ""
|
||||
md_output += f"| [{name}]({link}){tags} | {description} | {app_platforms} | {stars_formatted} |\n"
|
||||
md_output += "\n"
|
||||
return md_output
|
||||
|
||||
if __name__ == "__main__":
|
||||
# For testing, default to 'all' platforms
|
||||
print(generate_contents("all"))
|
||||
26
source/scripts/generation/mainheader_generator.py
Normal file
26
source/scripts/generation/mainheader_generator.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import json
|
||||
|
||||
# Generates mainheader with dynamic project count
|
||||
def generate_mainheader():
|
||||
with open("source/data/applications.json", "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
project_count = len(data.get("applications", []))
|
||||
|
||||
header_content = f"""
|
||||
<table align="center">
|
||||
<tr>
|
||||
<td>🇺🇦 v0.5.2-beta</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h1 align="center">[ definitive-opensource ] </h1>
|
||||
<p align="center">The definitive list of the best of everything open source</p>
|
||||
|
||||
<p align="center"><code>Status: Active</code> - <code>Projects: {project_count}</code></p>
|
||||
"""
|
||||
|
||||
return header_content
|
||||
|
||||
if __name__ == "__main__":
|
||||
generate_mainheader()
|
||||
54
source/scripts/generation/readme_generator.py
Normal file
54
source/scripts/generation/readme_generator.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import os
|
||||
from tableofcontents_generator import generate_table_of_contents
|
||||
from contents_generator import generate_contents
|
||||
from mainheader_generator import generate_mainheader
|
||||
|
||||
# List of target platforms
|
||||
platforms = ["all", "windows", "macos", "linux", "selfhost"]
|
||||
|
||||
# Platforms mapped to corresponding header files
|
||||
header_files = {
|
||||
"all": "source/components/header.md",
|
||||
"windows": "source/components/windowsheader.md",
|
||||
"macos": "source/components/macosheader.md",
|
||||
"linux": "source/components/linuxheader.md",
|
||||
"selfhost": "source/components/selfhostheader.md"
|
||||
}
|
||||
|
||||
def generate_readme_for_platform(platform):
|
||||
content = ""
|
||||
header_file = header_files.get(platform, "source/components/header.md")
|
||||
|
||||
# Inject mainheader with dynamic project count
|
||||
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("source/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("source/components/footer.md", "r", encoding="utf-8") as f:
|
||||
content += f.read() + "\n"
|
||||
|
||||
# Write output file
|
||||
output_filename = "README.md" if platform == "all" else f"readmes/{platform}.md"
|
||||
with open(output_filename, "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
print(f"Generated {output_filename}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
for platform in platforms:
|
||||
generate_readme_for_platform(platform)
|
||||
69
source/scripts/generation/tableofcontents_generator.py
Normal file
69
source/scripts/generation/tableofcontents_generator.py
Normal file
@@ -0,0 +1,69 @@
|
||||
import json
|
||||
|
||||
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("source/data/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}
|
||||
# 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:
|
||||
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"]
|
||||
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>
|
||||
<summary><b>Alphabetical</b></summary> <br />
|
||||
|
||||
{alphabetical_md}
|
||||
</details>
|
||||
|
||||
<details open>
|
||||
<summary><b>Categorized</b></summary> <br />
|
||||
|
||||
{categorized_md}
|
||||
</details>
|
||||
"""
|
||||
return toc
|
||||
|
||||
if __name__ == "__main__":
|
||||
# For testing the TOC generator
|
||||
print(generate_table_of_contents())
|
||||
Reference in New Issue
Block a user