Created
May 12, 2025 18:14
-
-
Save themorgantown/e6ce9118389da0e0417533f1669ccd6d to your computer and use it in GitHub Desktop.
cleanup semplice small layouts (favor large layouts)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, re, pathlib | |
SMALL_KEYS = {"sm", "xs"} | |
def strip_small(obj): | |
if isinstance(obj, dict): | |
cleaned = {} | |
for k, v in obj.items(): | |
# nuke breakpoint keys | |
if k in SMALL_KEYS: | |
continue | |
# nuke layout flags for mobile | |
if re.search(r"-(sm|xs)$", k): | |
continue | |
# recurse | |
cleaned[k] = strip_small(v) | |
return cleaned | |
elif isinstance(obj, list): | |
return [strip_small(i) for i in obj] | |
return obj | |
src = pathlib.Path("original.json").read_text() | |
desktop_only = strip_small(json.loads(src)) | |
out = pathlib.Path("original-fixed.json") | |
out.write_text(json.dumps(desktop_only, indent=2)) | |
print(f"Wrote {out.resolve()}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment