export function summarize()

in tools/gsuite-scanner/src/data/content.ts [56:78]


export function summarize(site: ISite, content: ISiteContent[]): ISiteWithContentSummary {

    const lastUpdated = content.map(c => c.updated).reduce((prev, cur) => cur > prev ? cur : prev, new Date(0));

    const cats = content.map(c => c.category).reduce((prev, cur) => {
        const index = prev.findIndex(i => i.name === cur);
        if (index < 0) {
            prev.push({ name: cur, count: 1 });
        } else {
            prev[index].count++;
        }
        return prev;
    }, <{ name: string, count: number }[]>[]);

    // augment the site with the summary information
    return Object.assign(site, {
        contentSummary: {
            categories: cats,
            count: content.length,
            lastModified: lastUpdated,
        },
    });
}