Add public/private news system with homepage display

This commit is contained in:
Torsten Schulz (local)
2025-10-21 15:26:28 +02:00
parent f0b628d746
commit 72c1039aa3
28 changed files with 272 additions and 126 deletions

View File

@@ -0,0 +1,25 @@
import { readNews } from '../utils/news.js'
export default defineEventHandler(async (event) => {
try {
const allNews = await readNews()
// Filter only public news
const publicNews = allNews.filter(item => item.isPublic === true)
// Sort by created date, newest first
publicNews.sort((a, b) => new Date(b.created) - new Date(a.created))
// Limit to latest 3 for homepage
const latestNews = publicNews.slice(0, 3)
return {
success: true,
news: latestNews
}
} catch (error) {
console.error('Fehler beim Abrufen der öffentlichen News:', error)
throw error
}
})