From ea99f65c26e476b3b10c9ae5047e0f2941e9c019 Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Sat, 17 Dec 2022 17:42:29 -0500 Subject: Icon and image for Identity could be a list --- core/ld.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'core/ld.py') diff --git a/core/ld.py b/core/ld.py index 24088ec..946e030 100644 --- a/core/ld.py +++ b/core/ld.py @@ -456,6 +456,20 @@ def parse_ld_date(value: str | None) -> datetime.datetime | None: ) +def get_first_image_url(data) -> str | None: + """ + 'icon' and 'image' fields might be a dict or a list. Return the first + 'url' for something that looks to be for an image. + """ + if isinstance(data, list): + for itm in data: + if isinstance(itm, dict) and "url" in itm: + return itm["url"] + elif isinstance(data, dict): + return data.get("url") + return None + + def media_type_from_filename(filename): _, extension = os.path.splitext(filename) if extension == ".png": -- cgit v1.2.3