const EMPTY = { messages: [] as any[] }

export default defineEventHandler(async () => {
  const data = await readDataYaml<{ messages: any[] }>('messages.yml', EMPTY)
  return data.messages
    .filter(m => m.published)
    .sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
})
