export function generateLlmsTxt(config, pages) {
    const maxPages = config.maxPages ?? 50;
    const lines = [];
    lines.push(`# ${config.siteName}`);
    lines.push('');
    if (config.siteDescription) {
        lines.push(`> ${config.siteDescription}`);
        lines.push('');
    }
    const sorted = [...pages].sort((a, b) => {
        if (a.isCornerstone !== b.isCornerstone)
            return a.isCornerstone ? -1 : 1;
        if (a.updatedAt && b.updatedAt)
            return b.updatedAt.localeCompare(a.updatedAt);
        if (a.updatedAt)
            return -1;
        if (b.updatedAt)
            return 1;
        return 0;
    });
    const limited = sorted.slice(0, maxPages);
    const groups = new Map();
    for (const page of limited) {
        const key = page.collection ?? 'Important Pages';
        let group = groups.get(key);
        if (!group) {
            group = [];
            groups.set(key, group);
        }
        group.push(page);
    }
    // Sort within each group: cornerstone first, then by updatedAt desc
    for (const group of groups.values()) {
        group.sort((a, b) => {
            if (a.isCornerstone !== b.isCornerstone)
                return a.isCornerstone ? -1 : 1;
            if (a.updatedAt && b.updatedAt)
                return b.updatedAt.localeCompare(a.updatedAt);
            if (a.updatedAt)
                return -1;
            if (b.updatedAt)
                return 1;
            return 0;
        });
    }
    for (const [collection, group] of groups) {
        const heading = formatHeading(collection);
        lines.push(`## ${heading}`);
        lines.push('');
        for (const page of group) {
            const entry = page.description
                ? `- [${page.title}](${page.url}): ${page.description}`
                : `- [${page.title}](${page.url})`;
            lines.push(entry);
        }
        lines.push('');
    }
    lines.push('## Resources');
    lines.push('');
    lines.push(`- [Sitemap](${config.siteUrl}/sitemap.xml)`);
    lines.push(`- [API Documentation](${config.siteUrl}/api/cms/docs)`);
    lines.push('');
    return lines.join('\n');
}
function formatHeading(collection) {
    return collection.replace(/[-_]/g, ' ').replace(/\b\w/g, (ch) => ch.toUpperCase());
}
//# sourceMappingURL=llms-txt.js.map