diff --git a/components/Views.tsx b/components/Views.tsx index 11e19c3..62872cd 100644 --- a/components/Views.tsx +++ b/components/Views.tsx @@ -1,17 +1,12 @@ +import useSWR from 'swr' import {ElementType, useEffect} from 'react' import fetcher from '@/lib/fetcher' -import useSWR from 'swr' +import {numberFormat} from '@/lib/numberFormat' type ViewsType = { views: string } -function numberFormat(value: number) { - return new Intl.NumberFormat('en', { - notation: 'compact' - }).format(value) -} - const updateViews = (slug: string) => fetcher(`/api/views/${slug}`, {method: 'POST'}) export function Views({as: Component = 'span', slug}: { as?: ElementType, slug: string }) { diff --git a/lib/numberFormat.ts b/lib/numberFormat.ts new file mode 100644 index 0000000..9bc36b5 --- /dev/null +++ b/lib/numberFormat.ts @@ -0,0 +1,5 @@ +export function numberFormat(value: number) { + return new Intl.NumberFormat('en', { + notation: 'compact' + }).format(value) +} \ No newline at end of file diff --git a/pages/projects.tsx b/pages/projects.tsx index 08fcb2c..a27e31d 100644 --- a/pages/projects.tsx +++ b/pages/projects.tsx @@ -5,6 +5,7 @@ import {SimpleLayout} from '@/components/SimpleLayout' import {SocialLink} from '@/components/SocialLink' import {StarIcon} from '@/components/StarIcon' import {getPinnedRepos} from '@/lib/github' +import {numberFormat} from '@/lib/numberFormat' import type {Repo} from '@/types' export default function Projects({pinnedRepos}: { pinnedRepos: Repo[] }) { @@ -50,7 +51,7 @@ export default function Projects({pinnedRepos}: { pinnedRepos: Repo[] }) { style={{backgroundColor: repo.primaryLanguage.color}}/>

- {repo.stargazerCount} + {numberFormat(repo.stargazerCount)}