Fixed backticks still in applications.json platform tags

This commit is contained in:
Lucas
2025-03-22 16:54:04 -07:00
parent c242bc20f3
commit 65a5c66720
10 changed files with 654 additions and 657 deletions

View File

@@ -1,23 +1,18 @@
import json
def slugify(name):
"""
Convert a string to an anchor-friendly slug.
"""
# Converts string to an anchor-friendly slug
return name.lower().replace(" ", "-").replace("(", "").replace(")", "")
def extract_repo_path(link):
"""
Extract the GitHub repository path from the URL.
Expects links of the form: https://github.com/username/repo
"""
# Extract the GitHub repository path from the URL. Link format: https://github.com/username/repo
parts = link.rstrip("/").split("/")
if len(parts) >= 5:
return f"{parts[-2]}/{parts[-1]}"
return ""
def generate_contents(platform="all"):
# Load categories and applications JSON data.
# Load categories and applications JSON data
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:
@@ -27,10 +22,10 @@ def generate_contents(platform="all"):
subcategories = cat_data.get("subcategories", [])
applications = app_data.get("applications", [])
# Build a mapping of parent category id to parent category name.
# Map parent categories id to corresponding name
parent_map = {cat["id"]: cat["Name"] for cat in categories}
# Group subcategories by their parent.
# Group subcategories by their parent
subcat_by_parent = {}
for sub in subcategories:
parent = sub.get("parent", "other")
@@ -38,23 +33,24 @@ def generate_contents(platform="all"):
"Name": sub["Name"],
"id": sub["id"]
})
# Sort subcategories alphabetically in each parent group.
# Sort subcategories alphabetically in each parent group
for key in subcat_by_parent:
subcat_by_parent[key].sort(key=lambda x: x["Name"].lower())
# Filter and group applications by their subcategory (identified by the app's "category" field).
# Filter and group applications by their subcategory
apps_by_subcat = {}
for app in applications:
include = False
if platform == "all":
include = True
else:
# Normalize platform tags by stripping backticks and comparing in lower-case.
app_platforms = [p.strip("`").lower() for p in app.get("platforms", [])]
# Compare platform tags in lower case
app_platforms = [p.lower() for p in app.get("platforms", [])]
target = platform.lower()
if target in app_platforms:
include = True
# For macos, linux, and windows, also include if "cross" is present.
# Include "Cross" apps for select platforms
if target in ["macos", "linux", "windows"] and "cross" in app_platforms:
include = True
if not include:
@@ -63,13 +59,13 @@ def generate_contents(platform="all"):
cat_id = app.get("category", "uncategorized")
apps_by_subcat.setdefault(cat_id, []).append(app)
# Sort applications within each subcategory alphabetically by name.
# Sort applications within each subcategory alphabetically by name
for key in apps_by_subcat:
apps_by_subcat[key].sort(key=lambda x: x["name"].lower())
# Build Markdown output.
md_output = ""
# Process parent categories: sort alphabetically (excluding "other", which is added last).
# Process parent categories: sort alphabetically (excluding "other", which is added last)
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:
@@ -77,13 +73,13 @@ def generate_contents(platform="all"):
for pid, pname in parent_items:
md_output += f"# {pname} - [Go to top](#contents)\n\n"
# For each subcategory under the parent category.
# For each subcategory under the parent category
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"
# List all apps for the given subcategory.
# List all apps for the given subcategory
apps = apps_by_subcat.get(sub["id"], [])
for app in apps:
name = app.get("name", "")
@@ -92,8 +88,8 @@ def generate_contents(platform="all"):
tags = ""
if app.get("tags"):
tags += " " + " ".join(app["tags"])
# Join the platform tags as provided.
app_platforms = " ".join(app.get("platforms", []))
# Join the platform tags as provided
app_platforms = " ".join(f"`{p}`" for p in app.get("platforms", []))
repo_path = extract_repo_path(link)
stars_badge = f"![GitHub Repo stars](https://img.shields.io/github/stars/{repo_path}?style=for-the-badge&label=%20&color=white)" if repo_path else ""
md_output += f"| [{name}]({link}){tags} | {description} | {app_platforms} | {stars_badge} |\n"
@@ -101,5 +97,5 @@ def generate_contents(platform="all"):
return md_output
if __name__ == "__main__":
# For testing, default to 'all' platforms.
# For testing, default to 'all' platforms
print(generate_contents("all"))

View File

@@ -1,5 +1,6 @@
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)

View File

@@ -6,7 +6,7 @@ from mainheader_generator import generate_mainheader
# List of target platforms
platforms = ["all", "windows", "macos", "linux", "selfhost"]
# Map platform to the header file to use
# Platforms mapped to corresponding header files
header_files = {
"all": "source/components/header.md",
"windows": "source/components/windowsheader.md",
@@ -23,7 +23,7 @@ def generate_readme_for_platform(platform):
if platform == "all":
content += generate_mainheader()
# Inject header (for 'all', use header.md; for others, use the platform-specific header)
# Inject header
with open(header_file, "r", encoding="utf-8") as f:
content += f.read() + "\n"
@@ -31,7 +31,7 @@ def generate_readme_for_platform(platform):
with open("source/components/tags.md", "r", encoding="utf-8") as f:
content += f.read() + "\n"
# Generate Table of Contents using the imported function
# Generate Table of Contents
toc_md = generate_table_of_contents()
content += toc_md + "\n"

View File

@@ -1,7 +1,7 @@
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():
@@ -18,15 +18,15 @@ def generate_table_of_contents():
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.
# 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.
# 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.
# 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)
@@ -41,7 +41,7 @@ def generate_table_of_contents():
for subname in grouped[pid]:
categorized_md_lines.append(f" - [{subname}](#{slugify(subname)})")
# Append fixed sections at the end of the categorized TOC.
# 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)})")