--- import MainLayout from '../layouts/MainLayout.astro'; import { getChurchName, fetchCurrentBulletinJson, fetchBulletinsJson } from '../lib/bindings.js'; let churchName = 'Church'; let currentBulletin = null; let bulletins = []; try { churchName = getChurchName(); // Get all bulletins first const bulletinsJson = fetchBulletinsJson(); bulletins = JSON.parse(bulletinsJson); // Find the most appropriate current bulletin // Either today's bulletin or the next upcoming one const today = new Date(); const todayString = today.toISOString().split('T')[0]; // YYYY-MM-DD format // Sort bulletins by date (newest first) const sortedBulletins = bulletins.sort((a, b) => new Date(b.date) - new Date(a.date)); // Find current bulletin: either today's or the next upcoming one currentBulletin = sortedBulletins.find(bulletin => bulletin.date >= todayString); // If no upcoming bulletin found, use the most recent one if (!currentBulletin && sortedBulletins.length > 0) { currentBulletin = sortedBulletins[0]; } // Try the API's current bulletin as fallback if (!currentBulletin) { const currentBulletinJson = fetchCurrentBulletinJson(); currentBulletin = JSON.parse(currentBulletinJson); } console.log('📰 Successfully loaded bulletin data:', { currentBulletin: currentBulletin ? `${currentBulletin.title} (${currentBulletin.date})` : 'none', bulletinCount: bulletins.length, todayDate: todayString }); } catch (e) { console.error('Failed to load bulletin data:', e); } // Format date from bulletin data const formatBulletinDate = (dateString) => { if (!dateString) return new Date().toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); const date = new Date(dateString + 'T00:00:00'); return date.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); }; const displayDate = currentBulletin ? formatBulletinDate(currentBulletin.date) : formatBulletinDate(null); const bulletinTitle = currentBulletin?.title || 'Weekly Bulletin'; // Parse service information const parseSabbathSchool = (text) => { if (!text) return null; const lines = text.split('\n').filter(line => line.trim()); const result = {}; let currentKey = ''; lines.forEach(line => { if (line.includes(':')) { currentKey = line.replace(':', '').trim(); result[currentKey] = ''; } else if (currentKey && line.trim()) { result[currentKey] = line.trim(); } }); return result; }; const parseDivineWorship = (text) => { if (!text) return null; const lines = text.split('\n').filter(line => line.trim()); const result = {}; let currentKey = ''; lines.forEach(line => { if (line.includes(':')) { currentKey = line.replace(':', '').trim(); result[currentKey] = ''; } else if (currentKey && line.trim()) { if (result[currentKey]) { result[currentKey] += '\n' + line.trim(); } else { result[currentKey] = line.trim(); } } }); return result; }; const sabbathSchoolInfo = currentBulletin ? parseSabbathSchool(currentBulletin.sabbath_school) : null; const divineWorshipInfo = currentBulletin ? parseDivineWorship(currentBulletin.divine_worship) : null; ---

{bulletinTitle}

Stay informed with our weekly church bulletin featuring service details, announcements, and community updates

{displayDate} {currentBulletin?.pdf_path && ( Download PDF )}

Sabbath Services

Sabbath School

9:30 AM - 10:45 AM
{sabbathSchoolInfo && Object.entries(sabbathSchoolInfo).map(([key, value]) => (
{key}: {value}
))}

Divine Service

11:00 AM - 12:15 PM
{divineWorshipInfo && Object.entries(divineWorshipInfo).map(([key, value]) => (
{key}:
{value}
))}

This Week's Focus

{currentBulletin?.scripture_reading && (

Scripture Reading

{currentBulletin.scripture_reading}
)} {divineWorshipInfo?.Sermon && (

Sermon

{divineWorshipInfo.Sermon}
)} {currentBulletin?.sunset && (

Sunset Times

{currentBulletin.sunset}
)}
{bulletins && bulletins.length > 1 && (

Recent Bulletins

View our previous weekly bulletins

{bulletins.slice(0, 6).map((bulletin) => (

{bulletin.title}

{formatBulletinDate(bulletin.date)}

View {bulletin.pdf_path && ( PDF )}
))}
{bulletins.length > 6 && ( )}
)}

Stay Connected

Have prayer requests or questions? We're here for you.