From 2b5618a4dab8c08fc0128efc5f817a0abf383139 Mon Sep 17 00:00:00 2001 From: Joshua Ryder Date: Thu, 2 Oct 2025 00:17:18 -0400 Subject: [PATCH] Fix sermon selection to exclude future dates - show most recent sermon up to today --- pages/index.vue | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 010a819..b9311e8 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -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