| 1 |
( function () { |
| 2 |
document.addEventListener('DOMContentLoaded', function () { |
| 3 |
document.querySelectorAll('.bkec-wrap[data-schema="1"]').forEach(function (wrap) { |
| 4 |
var raw = wrap.dataset.event; |
| 5 |
if (!raw) return; |
| 6 |
var e; |
| 7 |
try { e = JSON.parse(raw); } catch(err) { return; } |
| 8 |
|
| 9 |
var schema = { |
| 10 |
'@context': 'https://schema.org', |
| 11 |
'@type': 'Event', |
| 12 |
'name': e.name || '', |
| 13 |
'description': e.description || '', |
| 14 |
'startDate': e.startDate && e.startTime ? e.startDate + 'T' + e.startTime : e.startDate, |
| 15 |
'endDate': e.endDate && e.endTime ? e.endDate + 'T' + e.endTime : e.endDate, |
| 16 |
'eventStatus': 'https://schema.org/EventScheduled', |
| 17 |
'eventAttendanceMode': e.eventType === 'Virtual' |
| 18 |
? 'https://schema.org/OnlineEventAttendanceMode' |
| 19 |
: e.eventType === 'Hybrid' |
| 20 |
? 'https://schema.org/MixedEventAttendanceMode' |
| 21 |
: 'https://schema.org/OfflineEventAttendanceMode', |
| 22 |
'url': e.url || undefined, |
| 23 |
}; |
| 24 |
|
| 25 |
if (e.venueName) { |
| 26 |
schema.location = { |
| 27 |
'@type': 'Place', |
| 28 |
'name': e.venueName, |
| 29 |
'address': { '@type': 'PostalAddress', 'streetAddress': e.venueAddress || '' } |
| 30 |
}; |
| 31 |
} |
| 32 |
if (e.organizer) { |
| 33 |
schema.organizer = { '@type': 'Organization', 'name': e.organizer }; |
| 34 |
} |
| 35 |
if (e.image) schema.image = e.image; |
| 36 |
|
| 37 |
schema = JSON.parse(JSON.stringify(schema)); |
| 38 |
|
| 39 |
var script = document.createElement('script'); |
| 40 |
script.type = 'application/ld+json'; |
| 41 |
script.textContent = JSON.stringify(schema); |
| 42 |
document.head.appendChild(script); |
| 43 |
}); |
| 44 |
}); |
| 45 |
}() ); |
| 46 |
|