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:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user