From 495e955378d62dc439c4c210785e5d401bc77f64 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 16 Nov 2022 06:53:39 -0700 Subject: Tag and visibility handling --- core/ld.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core/ld.py') diff --git a/core/ld.py b/core/ld.py index 346708c..6692dab 100644 --- a/core/ld.py +++ b/core/ld.py @@ -414,6 +414,18 @@ def canonicalise(json_data: Dict, include_security: bool = False) -> Dict: return jsonld.compact(jsonld.expand(json_data), context) +def get_list(container, key) -> List: + """ + Given a JSON-LD value (that can be either a list, or a dict if it's just + one item), always returns a list""" + if key not in container: + return [] + value = container[key] + if not isinstance(value, list): + return [value] + return value + + def format_ld_date(value: datetime.datetime) -> str: return value.strftime(DATETIME_FORMAT) -- cgit v1.2.3