Skip to content

Commit dcb7aed

Browse files
committed
Try Sessionize v2 API endpoint with more flexible data parsing
1 parent 9ea6cf7 commit dcb7aed

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

speaking/index.html

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -662,52 +662,57 @@ <h3>Interested in having me speak at your event?</h3>
662662
</style>
663663

664664
<script>
665-
// Fetch and display next speaking engagement
666-
fetch('https://sessionize.com/api/speaker/json/8zkgq232gg')
665+
// Fetch and display next speaking engagement from Sessionize view-source API
666+
fetch('https://sessionize.com/api/v2/8zkgq232gg/view/Sessions')
667667
.then(response => response.json())
668668
.then(data => {
669669
console.log('Sessionize API response:', data); // Debug log
670670
const container = document.getElementById('next-event-container');
671671

672-
// Find the next upcoming event
673672
let nextEvent = null;
674673
const now = new Date();
675-
676-
// Try to find upcoming sessions or events
677674
let upcomingItems = [];
678675

679-
// Check for sessions
680-
if (data.sessions && data.sessions.length > 0) {
681-
upcomingItems = data.sessions
682-
.filter(session => {
683-
if (!session.startsAt) return false;
684-
const sessionDate = new Date(session.startsAt);
685-
return sessionDate >= now;
686-
})
687-
.map(session => ({
688-
...session,
689-
type: 'session'
690-
}));
691-
}
676+
// Parse the response - it could be an array or nested object
677+
let sessions = [];
692678

693-
// Check for events (if sessions not found or empty)
694-
if (upcomingItems.length === 0 && data.events && data.events.length > 0) {
695-
upcomingItems = data.events
696-
.filter(event => {
697-
if (!event.startDate && !event.endDate) return false;
698-
const eventDate = new Date(event.startDate || event.endDate);
699-
return eventDate >= now;
700-
})
701-
.map(event => ({
702-
title: event.name,
703-
description: event.description,
704-
startsAt: event.startDate,
705-
room: event.location,
706-
categories: event.categories || [],
707-
type: 'event'
708-
}));
679+
// Try different possible structures
680+
if (Array.isArray(data)) {
681+
// If data is directly an array
682+
sessions = data;
683+
} else if (data.sessions && Array.isArray(data.sessions)) {
684+
sessions = data.sessions;
685+
} else if (data.groupedSessions && Array.isArray(data.groupedSessions)) {
686+
// Flatten grouped sessions
687+
sessions = data.groupedSessions.flatMap(group => group.sessions || []);
688+
} else if (data.data && Array.isArray(data.data)) {
689+
sessions = data.data;
709690
}
710691

692+
// Find upcoming sessions
693+
sessions.forEach(session => {
694+
// Check various date field names that Sessionize might use
695+
const dateStr = session.startsAt || session.startTime || session.sessionStartTime ||
696+
session.startDate || session.starts || session.date;
697+
698+
if (dateStr) {
699+
try {
700+
const sessionDate = new Date(dateStr);
701+
if (sessionDate >= now && !isNaN(sessionDate.getTime())) {
702+
upcomingItems.push({
703+
title: session.title || session.name || session.sessionTitle || 'Untitled Session',
704+
description: session.description || session.sessionDescription || '',
705+
startsAt: dateStr,
706+
room: session.room || session.roomName || session.location || '',
707+
categories: session.categories || session.tags || []
708+
});
709+
}
710+
} catch (e) {
711+
console.warn('Error parsing date:', dateStr, e);
712+
}
713+
}
714+
});
715+
711716
// Sort by date and get the next one
712717
if (upcomingItems.length > 0) {
713718
upcomingItems.sort((a, b) => new Date(a.startsAt) - new Date(b.startsAt));
@@ -747,9 +752,12 @@ <h3 class="event-title">${nextEvent.title}</h3>
747752
</div>
748753
${nextEvent.categories && nextEvent.categories.length > 0 ? `
749754
<div class="event-tags">
750-
${nextEvent.categories.map(cat =>
751-
cat.categoryItems ? cat.categoryItems.map(item => `<span class="event-tag">${item.name}</span>`).join('') : ''
752-
).join('')}
755+
${nextEvent.categories.map(cat => {
756+
if (typeof cat === 'string') return `<span class="event-tag">${cat}</span>`;
757+
if (cat.categoryItems) return cat.categoryItems.map(item => `<span class="event-tag">${item.name || item}</span>`).join('');
758+
if (cat.name) return `<span class="event-tag">${cat.name}</span>`;
759+
return '';
760+
}).join('')}
753761
</div>` : ''}
754762
`;
755763
} else {

0 commit comments

Comments
 (0)