Fix sermon selection to exclude future dates - show most recent sermon up to today

This commit is contained in:
2025-10-02 00:17:18 -04:00
parent 8df6f886f3
commit 2b5618a4da

View File

@@ -103,10 +103,26 @@ const { data: archivedSermons } = await useFetch('/api/sermons?includeArchived=t
const selectedSermonSlug = ref('')
// Get most recent non-archived sermon
// Get most recent non-archived sermon (closest to or on today's date, not future dates)
const mostRecentSermon = computed(() => {
if (!activeSermons.value || activeSermons.value.length === 0) return null
return activeSermons.value[0]
const today = new Date()
today.setHours(0, 0, 0, 0)
// Find the sermon with the most recent date that is not in the future
const validSermons = activeSermons.value.filter((s: any) => {
const sermonDate = new Date(s.date + 'T00:00:00')
sermonDate.setHours(0, 0, 0, 0)
return sermonDate.getTime() <= today.getTime()
})
// If no valid sermons (all are future dates), return the earliest future sermon
if (validSermons.length === 0) {
return activeSermons.value[activeSermons.value.length - 1]
}
return validSermons[0]
})
// Get archived sermons only for the previous sermons dropdown