Added spotify data to dashboard

This commit is contained in:
r-freeman 2023-01-30 21:06:04 +00:00
parent 7170e786dd
commit 4f435d613d
3 changed files with 24 additions and 3 deletions

5
json/data.json Normal file
View File

@ -0,0 +1,5 @@
{
"statsfm": {
"top_genre": "modern rock"
}
}

View File

@ -1,6 +1,7 @@
import {getTotalFollowers, getTotalRepos, getTotalStars} from '@/lib/github' import {getTotalFollowers, getTotalRepos, getTotalStars} from '@/lib/github'
import {getAllArticles} from '@/lib/getAllArticles' import {getAllArticles} from '@/lib/getAllArticles'
import {getViews} from '@/lib/views' import {getViews} from '@/lib/views'
import {getLocalData} from '@/lib/localData'
import {Metric} from '@/types' import {Metric} from '@/types'
export async function getDashboardData() { export async function getDashboardData() {
@ -12,8 +13,15 @@ export async function getDashboardData() {
const totalStars = await getTotalStars(totalRepos) const totalStars = await getTotalStars(totalRepos)
const totalArticles = (await getAllArticles()).length const totalArticles = (await getAllArticles()).length
const totalArticleViews = (await getViews()).views const totalArticleViews = (await getViews()).views
const {statsfm} = JSON.parse(await getLocalData())
const metrics: Metric[] = [ const metrics: Metric[] = [
{
title: "Top genre",
value: statsfm.top_genre,
group: "Spotify",
href: "https://spotify.com/"
},
{ {
title: "Repos", title: "Repos",
value: totalRepos, value: totalRepos,
@ -33,17 +41,18 @@ export async function getDashboardData() {
href: "https://github.com/r-freeman/" href: "https://github.com/r-freeman/"
}, },
{ {
title: "Total Articles", title: "Total articles",
value: totalArticles, value: totalArticles,
group: "Website", group: "Website",
href: "/writing" href: "/writing"
}, },
{ {
title: "Total Article Views", title: "Total article views",
value: totalArticleViews, value: totalArticleViews,
group: "Website", group: "Website",
href: "/writing" href: "/writing"
} },
] ]
// sort metrics into named groups // sort metrics into named groups

7
lib/localData.ts Normal file
View File

@ -0,0 +1,7 @@
import path from 'path'
import {promises as fs} from 'fs'
export async function getLocalData() {
const jsonDirectory = path.join(process.cwd(), 'json')
return await fs.readFile(jsonDirectory + '/data.json', 'utf8')
}