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