aboutsummaryrefslogtreecommitdiff
path: root/scripts/theme-studio/generate.py
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-24 05:39:06 -0400
committerCraig Jennings <c@cjennings.net>2026-06-24 05:39:06 -0400
commita98dc772708f33e90aaeb4572a13bf22d065a022 (patch)
treee8c3682b2c82b5840999b3ad49a2ec947c9a38dd /scripts/theme-studio/generate.py
parent11767454d306518997d06207f9fe792f7482ac50 (diff)
downloaddotemacs-a98dc772708f33e90aaeb4572a13bf22d065a022.tar.gz
dotemacs-a98dc772708f33e90aaeb4572a13bf22d065a022.zip
feat(theme-studio): capture the nerd-icons filetype legend (phase 1)
Add build-nerd-icons-legend.el, which resolves the curated v1 legend rows (glyph + owner color face per filetype) from the live nerd-icons alists and dumps them to nerd-icons-legend.json, a committed artifact like package-inventory.json. generate.py gains load_nerd_icons_legend, which validates the artifact and returns None — with a warning — when it is absent, malformed, empty, or missing a field, so the page can fall back to the generic nerd-icons app rather than error. Data only; the bespoke preview that renders it lands next. Claude-Session: https://claude.ai/code/session_01BqrdWUo9GcznYX2pZr76gZ
Diffstat (limited to 'scripts/theme-studio/generate.py')
-rw-r--r--scripts/theme-studio/generate.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/theme-studio/generate.py b/scripts/theme-studio/generate.py
index 6baa67a91..4f390a850 100644
--- a/scripts/theme-studio/generate.py
+++ b/scripts/theme-studio/generate.py
@@ -12,6 +12,38 @@ def read_text(name):
def read_json(name):
return json.loads(read_text(name))
+NERD_ICONS_LEGEND_FIELDS = ("key", "label", "face", "category", "glyph")
+
+def load_nerd_icons_legend(path=None):
+ """Return the nerd-icons legend rows, or None when the artifact is unusable.
+
+ The legend is captured by build-nerd-icons-legend.el into nerd-icons-legend.json.
+ Absent, malformed, empty, or carrying a row without all five string fields
+ (key/label/face/category/glyph) -> None, with a warning, so the caller falls
+ back to the generic nerd-icons app instead of erroring. nerd-icons not being
+ installed at capture time yields an empty/absent file, which lands here as None.
+ """
+ path = path or os.path.join(HERE, "nerd-icons-legend.json")
+ if not os.path.exists(path):
+ print(f"WARNING: nerd-icons legend absent ({path}); generic nerd-icons app")
+ return None
+ try:
+ with open(path) as src:
+ rows = json.load(src)
+ except (json.JSONDecodeError, OSError) as exc:
+ print(f"WARNING: nerd-icons legend malformed ({path}: {exc}); generic nerd-icons app")
+ return None
+ if not isinstance(rows, list) or not rows:
+ print(f"WARNING: nerd-icons legend empty ({path}); generic nerd-icons app")
+ return None
+ for row in rows:
+ if not (isinstance(row, dict)
+ and all(isinstance(row.get(f), str) and row.get(f)
+ for f in NERD_ICONS_LEGEND_FIELDS)):
+ print(f"WARNING: nerd-icons legend row invalid ({row!r}); generic nerd-icons app")
+ return None
+ return rows
+
def strip_exports(src):
"""Drop ES-module `export`/`import` lines so the body loads as a classic <script>.