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
}
})

View File

@@ -1,18 +1,20 @@
[
{
"id": "660e8400-e29b-41d4-a716-446655440001",
"title": "Alles neu",
"content": "Die seite ist brandneu",
"author": "Admin",
"created": "2025-10-21T12:49:29.710Z",
"updated": "2025-10-21T12:49:29.710Z"
},
{
"id": "660e8400-e29b-41d4-a716-446655440002",
"title": "Willkommen im Mitgliederbereich",
"content": "Hier finden Sie ab sofort alle internen Neuigkeiten und Ankündigungen des Harheimer TC.",
"author": "Vorstand",
"isPublic": false,
"created": "2025-01-15T10:00:00.000Z",
"updated": "2025-01-15T10:00:00.000Z"
},
{
"id": "660e8400-e29b-41d4-a716-446655440003",
"title": "Erfolgreicher Saisonstart 2025/26",
"content": "Mit fünf Herrenmannschaften starten wir erfolgreich in die neue Saison. Wir freuen uns auf spannende Spiele!",
"author": "Vorstand",
"isPublic": true,
"created": "2025-01-20T10:00:00.000Z",
"updated": "2025-01-20T10:00:00.000Z"
}
]
]

View File

@@ -69,6 +69,7 @@ export async function saveNews(newsData) {
const newItem = {
...newsData,
id: randomUUID(), // Cryptographically secure unique ID
isPublic: newsData.isPublic || false, // Default to internal
created: new Date().toISOString(),
updated: new Date().toISOString()
}