diff --git a/app/api/news/route.ts b/app/api/news/route.ts index fbad39b..18df599 100644 --- a/app/api/news/route.ts +++ b/app/api/news/route.ts @@ -7,11 +7,15 @@ const API_URL = 'http://172.16.0.104:8000'; function formatDateTime(dateStr: string): { displayDate: string, timestamp: string } { try { const date = new Date(dateStr); + + // Format like "17 avr." to match the Duties widget style const day = date.getDate(); - const month = date.toLocaleString('fr-FR', { month: 'short' }).toLowerCase(); + const month = date.toLocaleString('fr-FR', { month: 'short' }) + .toLowerCase() + .replace('.', ''); // Remove the dot that comes with French locale return { - displayDate: `${day} ${month}.`, + displayDate: `${day} ${month}.`, // Add the dot back for consistent styling timestamp: date.toLocaleString('fr-FR', { day: '2-digit', month: 'short', @@ -35,7 +39,7 @@ function truncateText(text: string, maxLength: number): string { // Helper function to format category function formatCategory(category: string): string { - if (!category) return 'GENERAL'; + if (!category) return null; // Return null to match the interface const categoryMap: { [key: string]: string } = { 'GLOBAL ISSUES - WORLD AFFAIRS': 'WORLD', 'UN NEWS - GLOBAL NEWS': 'UN NEWS', @@ -58,6 +62,17 @@ function formatSource(source: string): string { return sourceName.charAt(0).toUpperCase() + sourceName.slice(1); } +interface NewsItem { + id: number; + title: string; + displayDate: string; + timestamp: string; + source: string; + description: string | null; + category: string | null; + url: string; +} + export async function GET() { try { console.log('Fetching news from FastAPI server...'); @@ -75,12 +90,12 @@ export async function GET() { const articles = await response.json(); - const formattedNews = articles.map((article: any) => { + const formattedNews: NewsItem[] = articles.map((article: any) => { const { displayDate, timestamp } = formatDateTime(article.date); return { id: article.id, title: truncateText(article.title, 70), - description: truncateText(article.description, 100), + description: article.description ? truncateText(article.description, 100) : null, displayDate, timestamp, source: formatSource(article.source),