portfolio/lib/dashboard.ts

57 lines
1.7 KiB
TypeScript

import {getTotalFollowers, getTotalRepos, getTotalStars} from '@/lib/github'
import {getAllArticles} from '@/lib/getAllArticles'
import {getViews} from '@/lib/views'
import {CardProps} from '@/types'
export async function getDashboardData() {
const [totalRepos, totalFollowers] = await Promise.all([
getTotalRepos(),
getTotalFollowers()
])
const totalStars = await getTotalStars(totalRepos)
const totalArticles = (await getAllArticles()).length
const totalArticleViews = (await getViews()).views
const data: CardProps[] = [
{
title: "Repos",
metric: totalRepos,
group: "GitHub",
href: "https://github.com/r-freeman?tab=repositories"
},
{
title: "Followers",
metric: totalFollowers,
group: "GitHub",
href: "https://github.com/r-freeman?tab=followers"
},
{
title: "Stars",
metric: totalStars,
group: "GitHub",
href: "https://github.com/r-freeman/"
},
{
title: "Total Articles",
metric: totalArticles,
group: "Website",
href: "/writing"
},
{
title: "Total Article Views",
metric: totalArticleViews,
group: "Website",
href: "/writing"
}
]
const groups = data.reduce((acc: { [key: string]: CardProps[] }, item) => {
(acc[item.group] = acc[item.group] || []).push(item);
return acc
}, {} as { [key: string]: CardProps[] })
return Object.entries(groups).map(([groupName, groupItems]) => {
return {groupName, groupItems}
})
}