diff --git a/osmcal/templatetags/schema.py b/osmcal/templatetags/schema.py index fb6f09b..9e3b50e 100644 --- a/osmcal/templatetags/schema.py +++ b/osmcal/templatetags/schema.py @@ -19,6 +19,8 @@ def schema_block(evt): } if evt.end: data["endDate"] = evt.end_localized.isoformat() + if evt.description: + data["description"] = evt.description if evt.cancelled: data["eventStatus"] = "https://schema.org/EventCancelled" @@ -26,11 +28,41 @@ def schema_block(evt): data["eventStatus"] = "https://schema.org/EventScheduled" if evt.location: + addr = { + "@type": "PostalAddress", + "addressLocality": ", ".join( + filter( + lambda x: x is not None, + [ + evt.location_address.get("village"), + evt.location_address.get("town"), + evt.location_address.get("city"), + ], + ) + ), + } + if "country_code" in evt.location_address: + addr["addressCountry"] = evt.location_address.get("country_code").upper() + if "state" in evt.location_address: + addr["addressRegion"] = evt.location_address.get("state") + if "postcode" in evt.location_address: + addr["postalCode"] = evt.location_address.get("postcode") + if "road" in evt.location_address: + addr["streetAddress"] = ", ".join( + filter( + lambda x: x is not None, + [evt.location_address.get("house_number"), evt.location_address.get("road")], + ) + ) + data["location"] = { + "@type": "Place", "latitude": evt.location.y, "longitude": evt.location.x, - "address": evt.location_detailed_addr, + "address": addr, } + if evt.location_name: + data["location"]["name"] = evt.location_name if evt.link: data["url"] = evt.link