2023-01-28 21:24:05 +00:00
|
|
|
import {getTotalFollowers, getTotalRepos, getTotalStars} from '@/lib/github'
|
2023-01-28 21:59:01 +00:00
|
|
|
import {getAllArticles} from '@/lib/getAllArticles'
|
|
|
|
import {getViews} from '@/lib/views'
|
2023-01-29 23:04:28 +00:00
|
|
|
import {Metric} from '@/types'
|
2023-01-28 21:24:05 +00:00
|
|
|
|
2023-01-29 22:16:58 +00:00
|
|
|
export async function getDashboardData() {
|
2023-01-28 21:24:05 +00:00
|
|
|
const [totalRepos, totalFollowers] = await Promise.all([
|
|
|
|
getTotalRepos(),
|
|
|
|
getTotalFollowers()
|
|
|
|
])
|
|
|
|
|
|
|
|
const totalStars = await getTotalStars(totalRepos)
|
2023-01-29 11:24:06 +00:00
|
|
|
const totalArticles = (await getAllArticles()).length
|
|
|
|
const totalArticleViews = (await getViews()).views
|
2023-01-28 21:24:05 +00:00
|
|
|
|
2023-01-29 23:04:28 +00:00
|
|
|
const metrics: Metric[] = [
|
2023-01-28 21:24:05 +00:00
|
|
|
{
|
2023-01-29 22:16:58 +00:00
|
|
|
title: "Repos",
|
2023-01-29 23:04:28 +00:00
|
|
|
value: totalRepos,
|
2023-01-29 22:16:58 +00:00
|
|
|
group: "GitHub",
|
2023-01-28 23:04:49 +00:00
|
|
|
href: "https://github.com/r-freeman?tab=repositories"
|
2023-01-28 21:24:05 +00:00
|
|
|
},
|
|
|
|
{
|
2023-01-29 22:16:58 +00:00
|
|
|
title: "Followers",
|
2023-01-29 23:04:28 +00:00
|
|
|
value: totalFollowers,
|
2023-01-29 22:16:58 +00:00
|
|
|
group: "GitHub",
|
2023-01-28 23:04:49 +00:00
|
|
|
href: "https://github.com/r-freeman?tab=followers"
|
2023-01-28 21:24:05 +00:00
|
|
|
},
|
|
|
|
{
|
2023-01-29 22:16:58 +00:00
|
|
|
title: "Stars",
|
2023-01-29 23:04:28 +00:00
|
|
|
value: totalStars,
|
2023-01-29 22:16:58 +00:00
|
|
|
group: "GitHub",
|
2023-01-28 21:24:05 +00:00
|
|
|
href: "https://github.com/r-freeman/"
|
2023-01-28 21:59:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Total Articles",
|
2023-01-29 23:04:28 +00:00
|
|
|
value: totalArticles,
|
2023-01-29 22:16:58 +00:00
|
|
|
group: "Website",
|
2023-01-28 21:59:01 +00:00
|
|
|
href: "/writing"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Total Article Views",
|
2023-01-29 23:04:28 +00:00
|
|
|
value: totalArticleViews,
|
2023-01-29 22:16:58 +00:00
|
|
|
group: "Website",
|
2023-01-28 21:59:01 +00:00
|
|
|
href: "/writing"
|
2023-01-28 21:24:05 +00:00
|
|
|
}
|
|
|
|
]
|
2023-01-29 22:16:58 +00:00
|
|
|
|
2023-01-29 23:04:28 +00:00
|
|
|
// sort metrics into named groups
|
|
|
|
const groups = metrics.reduce((acc: { [key: string]: Metric[] }, item) => {
|
2023-01-29 22:16:58 +00:00
|
|
|
(acc[item.group] = acc[item.group] || []).push(item);
|
2023-01-29 22:32:21 +00:00
|
|
|
return acc
|
2023-01-29 23:04:28 +00:00
|
|
|
}, {} as { [key: string]: Metric[] })
|
2023-01-29 22:16:58 +00:00
|
|
|
|
|
|
|
return Object.entries(groups).map(([groupName, groupItems]) => {
|
|
|
|
return {groupName, groupItems}
|
|
|
|
})
|
2023-01-28 21:24:05 +00:00
|
|
|
}
|