import { getCollection } from 'astro:content';

import type { ProgressTeaserEntry } from '@/types/site';

export async function getRecentChangelogEntries(limit = 3): Promise<ProgressTeaserEntry[]> {
    const changelog = await getCollection('changelog');

    return changelog
        .filter((entry) => entry.data.draft !== true)
        .sort((a, b) => b.data.publishedAt.getTime() - a.data.publishedAt.getTime())
        .slice(0, limit)
        .map((entry) => ({
            date: entry.data.publishedAt,
            description: entry.data.description,
            title: entry.data.title,
        }));
}
