Enhance news component functionality and UI; implement dynamic grid layout in PublicNews.vue, add visibility and expiration options in news management, and update API to handle new fields for improved news filtering and display.

This commit is contained in:
Torsten Schulz (local)
2025-10-24 12:47:27 +02:00
parent bf97cfd508
commit 75e6919f13
5 changed files with 167 additions and 35 deletions

View File

@@ -3,9 +3,24 @@ import { readNews } from '../utils/news.js'
export default defineEventHandler(async (event) => {
try {
const allNews = await readNews()
const now = new Date()
// Filter only public news
const publicNews = allNews.filter(item => item.isPublic === true)
// Filter only public news that are not hidden and not expired
const publicNews = allNews.filter(item => {
// Must be public
if (!item.isPublic) return false
// Must not be hidden
if (item.isHidden) return false
// Must not be expired
if (item.expiresAt) {
const expiresAt = new Date(item.expiresAt)
if (expiresAt <= now) return false
}
return true
})
// Sort by created date, newest first
publicNews.sort((a, b) => new Date(b.created) - new Date(a.created))