diff --git a/pages/[slug].vue b/pages/[slug].vue index 239b628..2e7be0c 100644 --- a/pages/[slug].vue +++ b/pages/[slug].vue @@ -78,6 +78,23 @@ + +
+

Worship Songs

+
+ +
+
+
{ } }) +const worshipSongs = computed(() => { + if (!sermon.value?.worship_songs) return [] + try { + return JSON.parse(sermon.value.worship_songs) + } catch { + return [] + } +}) + // Font size classes const fontSizeClasses = computed(() => { switch (fontSize.value) { diff --git a/pages/admin.vue b/pages/admin.vue index fe0d5b7..591ce0b 100644 --- a/pages/admin.vue +++ b/pages/admin.vue @@ -111,7 +111,7 @@
+

This date will be used for the sermon URL and sorting

+
+ + +
+

Additional Dates

+

Add more dates if this sermon will be presented multiple times (e.g., Saturday and Sunday services)

+
+
+ + +
+ +
@@ -231,6 +262,57 @@ >
+ +
+

Worship Songs

+

Add songs that were sung during this service (optional)

+
+
+
+
+ + +
+
+ + +
+ +
+
+ +
+
+
{{ error }} @@ -280,6 +362,8 @@ const archiveSuccess = ref('') // Create sermon form state const editingSermonId = ref(null) const bibleReferences = ref([{ version: 'ESV', reference: '', text: '' }]) +const sermonDates = ref(['']) +const worshipSongs = ref([{ name: '', artist: '' }]) const formData = ref({ date: '', title: '', @@ -305,6 +389,22 @@ function removeReference(index: number) { bibleReferences.value.splice(index, 1) } +function addDate() { + sermonDates.value.push('') +} + +function removeDate(index: number) { + sermonDates.value.splice(index, 1) +} + +function addSong() { + worshipSongs.value.push({ name: '', artist: '' }) +} + +function removeSong(index: number) { + worshipSongs.value.splice(index, 1) +} + function formatDateToSlug(date: string) { // Convert YYYY-MM-DD to MMDDYYYY const [year, month, day] = date.split('-') @@ -324,13 +424,23 @@ async function handleSubmit() { ) const bible_references = JSON.stringify(validReferences) + // Filter valid dates and serialize as JSON + const validDates = sermonDates.value.filter(d => d) + const dates = validDates.length > 0 ? JSON.stringify(validDates) : null + + // Filter valid songs and serialize as JSON + const validSongs = worshipSongs.value.filter(s => s.name) + const worship_songs = validSongs.length > 0 ? JSON.stringify(validSongs) : null + const body = { slug, title: formData.value.title, date: formData.value.date, bible_references, personal_appliance: formData.value.personal_appliance, - pastors_challenge: formData.value.pastors_challenge + pastors_challenge: formData.value.pastors_challenge, + dates, + worship_songs } if (editingSermonId.value) { @@ -382,6 +492,8 @@ function cancelEdit() { pastors_challenge: '' } bibleReferences.value = [{ version: 'ESV', reference: '', text: '' }] + sermonDates.value = [''] + worshipSongs.value = [{ name: '', artist: '' }] } function handleEdit() { @@ -408,6 +520,20 @@ function handleEdit() { // Fallback for old format bibleReferences.value = [{ version: 'ESV', reference: sermon.bible_references, text: '' }] } + + // Parse and load additional dates + try { + sermonDates.value = sermon.dates ? JSON.parse(sermon.dates) : [''] + } catch { + sermonDates.value = [''] + } + + // Parse and load worship songs + try { + worshipSongs.value = sermon.worship_songs ? JSON.parse(sermon.worship_songs) : [{ name: '', artist: '' }] + } catch { + worshipSongs.value = [{ name: '', artist: '' }] + } // Scroll to form (just below the management section) const formElement = document.querySelector('form') diff --git a/pages/index.vue b/pages/index.vue index e7245a9..5edd5bc 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -123,9 +123,26 @@ const todaysSermon = computed(() => { today.setHours(0, 0, 0, 0) return activeSermons.value.find((s: any) => { + // Check primary date const sermonDate = new Date(s.date + 'T00:00:00') sermonDate.setHours(0, 0, 0, 0) - return sermonDate.getTime() === today.getTime() + if (sermonDate.getTime() === today.getTime()) return true + + // Check additional dates if they exist + if (s.dates) { + try { + const additionalDates = JSON.parse(s.dates) + return additionalDates.some((dateStr: string) => { + const additionalDate = new Date(dateStr + 'T00:00:00') + additionalDate.setHours(0, 0, 0, 0) + return additionalDate.getTime() === today.getTime() + }) + } catch { + return false + } + } + + return false }) || null }) @@ -137,9 +154,26 @@ const upcomingSermons = computed(() => { today.setHours(0, 0, 0, 0) return activeSermons.value.filter((s: any) => { + // Check primary date const sermonDate = new Date(s.date + 'T00:00:00') sermonDate.setHours(0, 0, 0, 0) - return sermonDate.getTime() > today.getTime() + if (sermonDate.getTime() > today.getTime()) return true + + // Check additional dates if they exist + if (s.dates) { + try { + const additionalDates = JSON.parse(s.dates) + return additionalDates.some((dateStr: string) => { + const additionalDate = new Date(dateStr + 'T00:00:00') + additionalDate.setHours(0, 0, 0, 0) + return additionalDate.getTime() > today.getTime() + }) + } catch { + return false + } + } + + return false }) }) diff --git a/server/api/sermons/index.post.ts b/server/api/sermons/index.post.ts index a1de744..fc07fee 100644 --- a/server/api/sermons/index.post.ts +++ b/server/api/sermons/index.post.ts @@ -11,7 +11,7 @@ export default defineEventHandler(async (event) => { } const body = await readBody(event) - const { slug, title, date, bible_references, personal_appliance, pastors_challenge } = body + const { slug, title, date, dates, bible_references, personal_appliance, pastors_challenge, worship_songs } = body if (!slug || !title || !date || !bible_references || !personal_appliance || !pastors_challenge) { throw createError({ @@ -25,9 +25,11 @@ export default defineEventHandler(async (event) => { slug, title, date, + dates, bible_references, personal_appliance, - pastors_challenge + pastors_challenge, + worship_songs }) return { diff --git a/server/api/sermons/update/[id].put.ts b/server/api/sermons/update/[id].put.ts index e87d8b9..2ac1a02 100644 --- a/server/api/sermons/update/[id].put.ts +++ b/server/api/sermons/update/[id].put.ts @@ -20,7 +20,7 @@ export default defineEventHandler(async (event) => { } const body = await readBody(event) - const { slug, title, date, bible_references, personal_appliance, pastors_challenge } = body + const { slug, title, date, dates, bible_references, personal_appliance, pastors_challenge, worship_songs } = body if (!slug || !title || !date || !bible_references || !personal_appliance || !pastors_challenge) { throw createError({ @@ -33,10 +33,10 @@ export default defineEventHandler(async (event) => { const db = getDatabase() const result = db.prepare(` UPDATE sermons - SET slug = ?, title = ?, date = ?, bible_references = ?, - personal_appliance = ?, pastors_challenge = ? + SET slug = ?, title = ?, date = ?, dates = ?, bible_references = ?, + personal_appliance = ?, pastors_challenge = ?, worship_songs = ? WHERE id = ? - `).run(slug, title, date, bible_references, personal_appliance, pastors_challenge, parseInt(id)) + `).run(slug, title, date, dates || null, bible_references, personal_appliance, pastors_challenge, worship_songs || null, parseInt(id)) if (result.changes === 0) { throw createError({ diff --git a/server/utils/database.ts b/server/utils/database.ts index 461ea57..802549b 100644 --- a/server/utils/database.ts +++ b/server/utils/database.ts @@ -8,9 +8,11 @@ export interface Sermon { slug: string title: string date: string + dates?: string bible_references: string personal_appliance: string pastors_challenge: string + worship_songs?: string created_at?: string } @@ -32,9 +34,11 @@ export function getDatabase() { slug TEXT UNIQUE NOT NULL, title TEXT NOT NULL, date TEXT NOT NULL, + dates TEXT, bible_references TEXT NOT NULL, personal_appliance TEXT NOT NULL, pastors_challenge TEXT NOT NULL, + worship_songs TEXT, archived INTEGER DEFAULT 0, created_at DATETIME DEFAULT CURRENT_TIMESTAMP ) @@ -87,16 +91,18 @@ export function getSermonBySlug(slug: string) { export function createSermon(sermon: Sermon) { const db = getDatabase() const stmt = db.prepare(` - INSERT INTO sermons (slug, title, date, bible_references, personal_appliance, pastors_challenge) - VALUES (?, ?, ?, ?, ?, ?) + INSERT INTO sermons (slug, title, date, dates, bible_references, personal_appliance, pastors_challenge, worship_songs) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) `) return stmt.run( sermon.slug, sermon.title, sermon.date, + sermon.dates || null, sermon.bible_references, sermon.personal_appliance, - sermon.pastors_challenge + sermon.pastors_challenge, + sermon.worship_songs || null ) }