Implement dynamic daily verse system with rotating Biblical content

- Add daily-verse API endpoint with 7 rotating verses in Romanian and English
- Replace static homepage verse with dynamic fetch from API
- Ensure consistent daily rotation using day-of-year calculation
- Support both ro and en locales for verse content

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Assistant
2025-09-22 19:22:34 +00:00
parent d4b0062521
commit ee99e93ec2
11 changed files with 4224 additions and 5 deletions

View File

@@ -0,0 +1,137 @@
import { NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
// Daily verses collection - you can expand this with more verses
const DAILY_VERSES = [
{
verse: "Căci Eu știu gândurile pe care le am cu privire la voi, zice Domnul, gânduri de pace și nu de rău, ca să vă dau un viitor și o speranță.",
reference: "Ieremia 29:11",
verseEn: "For I know the plans I have for you, declares the Lord, plans to prosper you and not to harm you, plans to give you hope and a future.",
referenceEn: "Jeremiah 29:11"
},
{
verse: "Încrede-te în Domnul din toată inima ta și nu te bizui pe înțelepciunea ta.",
reference: "Proverbe 3:5",
verseEn: "Trust in the Lord with all your heart and lean not on your own understanding.",
referenceEn: "Proverbs 3:5"
},
{
verse: "Pot totul în Hristos care mă întărește.",
reference: "Filipeni 4:13",
verseEn: "I can do all things through Christ who strengthens me.",
referenceEn: "Philippians 4:13"
},
{
verse: "Și știm că toate lucrurile lucrează împreună pentru binele celor ce iubesc pe Dumnezeu.",
reference: "Romani 8:28",
verseEn: "And we know that in all things God works for the good of those who love him.",
referenceEn: "Romans 8:28"
},
{
verse: "Nu te teme, căci Eu sunt cu tine; nu te uita cu îngrijorare, căci Eu sunt Dumnezeul tău!",
reference: "Isaia 41:10",
verseEn: "So do not fear, for I am with you; do not be dismayed, for I am your God.",
referenceEn: "Isaiah 41:10"
},
{
verse: "Domnul este păstorul meu: nu voi duce lipsă de nimic.",
reference: "Psalm 23:1",
verseEn: "The Lord is my shepherd, I lack nothing.",
referenceEn: "Psalm 23:1"
},
{
verse: "Bucurați-vă totdeauna în Domnul! Iarăși zic: Bucurați-vă!",
reference: "Filipeni 4:4",
verseEn: "Rejoice in the Lord always. I will say it again: Rejoice!",
referenceEn: "Philippians 4:4"
}
]
function getDailyVerse(date: Date, locale: string = 'ro') {
// Calculate day of year to ensure the same verse appears all day
const start = new Date(date.getFullYear(), 0, 0)
const diff = date.getTime() - start.getTime()
const dayOfYear = Math.floor(diff / (1000 * 60 * 60 * 24))
// Use day of year to select verse consistently
const verseIndex = dayOfYear % DAILY_VERSES.length
const selectedVerse = DAILY_VERSES[verseIndex]
const formatDate = (date: Date, locale: string) => {
if (locale === 'ro') {
return date.toLocaleDateString('ro-RO', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
} else {
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
}
}
return {
date: formatDate(date, locale),
verse: locale === 'ro' ? selectedVerse.verse : selectedVerse.verseEn,
reference: locale === 'ro' ? selectedVerse.reference : selectedVerse.referenceEn,
dayOfYear,
verseIndex
}
}
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const locale = searchParams.get('locale') || 'ro'
// Validate locale
if (!['ro', 'en'].includes(locale)) {
return NextResponse.json(
{ error: 'Invalid locale. Must be "ro" or "en".' },
{ status: 400 }
)
}
const today = new Date()
const dailyVerse = getDailyVerse(today, locale)
return NextResponse.json({
success: true,
data: dailyVerse
})
} catch (error) {
console.error('Daily verse API error:', error)
return NextResponse.json(
{
error: 'Failed to get daily verse',
message: error instanceof Error ? error.message : 'Unknown error'
},
{ status: 500 }
)
}
}
// Optional: Add POST endpoint to add new verses (for admin use)
export async function POST(request: NextRequest) {
try {
const body = await request.json()
// This would typically save to database
// For now, just return success
return NextResponse.json({
success: true,
message: 'Daily verse system is read-only for now'
})
} catch (error) {
console.error('Daily verse POST error:', error)
return NextResponse.json(
{ error: 'Failed to process request' },
{ status: 500 }
)
}
}