From 4f435d613debc310fed0544eabe38a811d1324f0 Mon Sep 17 00:00:00 2001 From: r-freeman Date: Mon, 30 Jan 2023 21:06:04 +0000 Subject: [PATCH] Added spotify data to dashboard --- json/data.json | 5 +++++ lib/dashboard.ts | 15 ++++++++++++--- lib/localData.ts | 7 +++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 json/data.json create mode 100644 lib/localData.ts diff --git a/json/data.json b/json/data.json new file mode 100644 index 0000000..6f2e1d5 --- /dev/null +++ b/json/data.json @@ -0,0 +1,5 @@ +{ + "statsfm": { + "top_genre": "modern rock" + } +} \ No newline at end of file diff --git a/lib/dashboard.ts b/lib/dashboard.ts index 9232e75..3dcb0bb 100644 --- a/lib/dashboard.ts +++ b/lib/dashboard.ts @@ -1,6 +1,7 @@ import {getTotalFollowers, getTotalRepos, getTotalStars} from '@/lib/github' import {getAllArticles} from '@/lib/getAllArticles' import {getViews} from '@/lib/views' +import {getLocalData} from '@/lib/localData' import {Metric} from '@/types' export async function getDashboardData() { @@ -12,8 +13,15 @@ export async function getDashboardData() { const totalStars = await getTotalStars(totalRepos) const totalArticles = (await getAllArticles()).length const totalArticleViews = (await getViews()).views + const {statsfm} = JSON.parse(await getLocalData()) const metrics: Metric[] = [ + { + title: "Top genre", + value: statsfm.top_genre, + group: "Spotify", + href: "https://spotify.com/" + }, { title: "Repos", value: totalRepos, @@ -33,17 +41,18 @@ export async function getDashboardData() { href: "https://github.com/r-freeman/" }, { - title: "Total Articles", + title: "Total articles", value: totalArticles, group: "Website", href: "/writing" }, { - title: "Total Article Views", + title: "Total article views", value: totalArticleViews, group: "Website", href: "/writing" - } + }, + ] // sort metrics into named groups diff --git a/lib/localData.ts b/lib/localData.ts new file mode 100644 index 0000000..1028658 --- /dev/null +++ b/lib/localData.ts @@ -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') +} \ No newline at end of file