diff options
author | 2018-04-11 20:39:48 +0100 | |
---|---|---|
committer | 2018-04-11 20:39:48 +0100 | |
commit | 592b8ec1f0b504b60965939045431d7989869073 (patch) | |
tree | e6e38f6ac0a787b066cd3a2a063b25fa28553dc5 /pysite | |
parent | Fix unit tests (diff) |
Update resources page with new icons and formatting.
NOTE: This does change the JSON!
Diffstat (limited to 'pysite')
-rw-r--r-- | pysite/views/main/info/resources.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/pysite/views/main/info/resources.py b/pysite/views/main/info/resources.py index ceb88b65..2642e1ec 100644 --- a/pysite/views/main/info/resources.py +++ b/pysite/views/main/info/resources.py @@ -4,9 +4,48 @@ from logging import getLogger from pysite.base_route import RouteView +ICON_STYLES = { + "branding": "fab", + "regular": "far", + "solid": "fas", + "light": "fal" +} + +logger = getLogger("Resources") + try: with open("static/resources.json") as fh: categories = json.load(fh) + + for category, items in categories.items(): + to_remove = [] + + for name, resource in items["resources"].items(): + for url_obj in resource["urls"]: + icon = url_obj["icon"].lower() + + if "/" not in icon: + to_remove.append(name) + logger.error( + f"Resource {name} in category {category} has an invalid icon. Icons should be of the" + f"form `style/name`." + ) + continue + + style, icon_name = icon.split("/") + + if style not in ICON_STYLES: + to_remove.append(name) + logger.error( + f"Resource {name} in category {category} has an invalid icon style. Icon style must " + f"be one of {', '.join(ICON_STYLES.keys())}." + ) + continue + + url_obj["classes"] = f"{ICON_STYLES[style]} fa-{icon_name}" + + for name in to_remove: + del items["resources"][name] except Exception: getLogger("Resources").exception("Failed to load resources.json") categories = None |