-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
103 lines (82 loc) · 2.88 KB
/
build.py
File metadata and controls
103 lines (82 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""Build script for hub.bub.build — generates a static page from data.yml + Jinja2 templates."""
import json
import shutil
import sys
from pathlib import Path
import yaml
from jinja2 import Environment, FileSystemLoader
ROOT = Path(__file__).parent
TEMPLATES_DIR = ROOT / "templates"
LOGOS_DIR = ROOT / "logos"
DIST_DIR = ROOT / "dist"
VALID_KINDS = {"plugin", "skill", "distribution", "friend"}
KNOWN_FIELDS = {
"name", "description", "kind", "logo",
"homepage_url", "repo_url", "docs_url",
"author", "license", "install",
"builtin", "source_path", "skill_file",
"bundled_plugins",
}
def load_data():
with open(ROOT / "data.yml") as f:
return yaml.safe_load(f)
def validate(categories):
errors = []
for cat in categories:
for sub in cat.get("subcategories", []):
for item in sub.get("items", []):
loc = f"{cat['name']}/{sub['name']}/{item.get('name', '?')}"
if not item.get("name"):
errors.append(f"{loc}: missing 'name'")
if not item.get("description"):
errors.append(f"{loc}: missing 'description'")
kind = item.get("kind")
if kind not in VALID_KINDS:
errors.append(f"{loc}: invalid kind '{kind}', expected one of {VALID_KINDS}")
unknown = set(item.keys()) - KNOWN_FIELDS
if unknown:
errors.append(f"{loc}: unknown fields {unknown}")
if errors:
print("Validation errors:", file=sys.stderr)
for e in errors:
print(f" - {e}", file=sys.stderr)
sys.exit(1)
def build():
data = load_data()
categories = data.get("categories", [])
validate(categories)
total_items = sum(
len(sub.get("items", []))
for cat in categories
for sub in cat.get("subcategories", [])
)
cat_counts = {}
for cat in categories:
cat_counts[cat.get("name", "")] = sum(
len(sub.get("items", []))
for sub in cat.get("subcategories", [])
)
env = Environment(
loader=FileSystemLoader(str(TEMPLATES_DIR)),
autoescape=True,
)
template = env.get_template("index.html")
html = template.render(
title="Bub Hub — Ecosystem Directory",
description="Ecosystem directory for Bub plugins, skills, distributions, and friends.",
categories=categories,
total_items=total_items,
cat_counts_json=json.dumps(cat_counts),
)
DIST_DIR.mkdir(exist_ok=True)
(DIST_DIR / "index.html").write_text(html)
# Copy logos
dist_logos = DIST_DIR / "logos"
if LOGOS_DIR.is_dir():
if dist_logos.exists():
shutil.rmtree(dist_logos)
shutil.copytree(LOGOS_DIR, dist_logos)
print(f"Built hub → {DIST_DIR / 'index.html'}")
if __name__ == "__main__":
build()