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:
@@ -49,6 +49,33 @@ export default function Home() {
|
||||
const [userCount, setUserCount] = useState(2847)
|
||||
const [expandedFaq, setExpandedFaq] = useState<string | false>(false)
|
||||
const [email, setEmail] = useState('')
|
||||
const [dailyVerse, setDailyVerse] = useState<{
|
||||
date: string
|
||||
verse: string
|
||||
reference: string
|
||||
} | null>(null)
|
||||
|
||||
// Fetch daily verse
|
||||
useEffect(() => {
|
||||
const fetchDailyVerse = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/daily-verse?locale=${locale}`)
|
||||
if (response.ok) {
|
||||
const result = await response.json()
|
||||
setDailyVerse(result.data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch daily verse:', error)
|
||||
// Fallback to static content if API fails
|
||||
setDailyVerse({
|
||||
date: getCurrentDate(),
|
||||
verse: t('dailyVerse.verse'),
|
||||
reference: t('dailyVerse.reference')
|
||||
})
|
||||
}
|
||||
}
|
||||
fetchDailyVerse()
|
||||
}, [locale, t])
|
||||
|
||||
// Simulate live user counter
|
||||
useEffect(() => {
|
||||
@@ -229,15 +256,15 @@ export default function Home() {
|
||||
{t('dailyVerse.title')}
|
||||
</Typography>
|
||||
<Typography variant="body2" textAlign="center" sx={{ mb: 4, opacity: 0.9 }}>
|
||||
{getCurrentDate()}
|
||||
{dailyVerse?.date || getCurrentDate()}
|
||||
</Typography>
|
||||
|
||||
<Paper sx={{ p: 4, textAlign: 'center', bgcolor: 'rgba(255,255,255,0.95)', color: 'text.primary', borderRadius: 3 }}>
|
||||
<Typography variant="h5" sx={{ mb: 3, fontStyle: 'italic', lineHeight: 1.6 }}>
|
||||
{t('dailyVerse.verse')}
|
||||
{dailyVerse?.verse || t('dailyVerse.verse')}
|
||||
</Typography>
|
||||
<Typography variant="h6" color="primary" sx={{ fontWeight: 600 }}>
|
||||
{t('dailyVerse.reference')}
|
||||
{dailyVerse?.reference || t('dailyVerse.reference')}
|
||||
</Typography>
|
||||
|
||||
<Box sx={{ display: 'flex', gap: 1, justifyContent: 'center', mt: 3 }}>
|
||||
@@ -245,8 +272,8 @@ export default function Home() {
|
||||
<IconButton
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
const verseText = t('dailyVerse.verse')
|
||||
const reference = t('dailyVerse.reference')
|
||||
const verseText = dailyVerse?.verse || t('dailyVerse.verse')
|
||||
const reference = dailyVerse?.reference || t('dailyVerse.reference')
|
||||
const discussMessage = locale === 'ro'
|
||||
? `Poți să îmi explici mai mult despre acest verset: "${verseText}" (${reference})?`
|
||||
: `Can you explain more about this verse: "${verseText}" (${reference})?`
|
||||
|
||||
137
app/api/daily-verse/route.ts
Normal file
137
app/api/daily-verse/route.ts
Normal 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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user