diff --git a/site/src/components/GitHubStars.tsx b/site/src/components/GitHubStars.tsx new file mode 100644 index 0000000000..004a5af89c --- /dev/null +++ b/site/src/components/GitHubStars.tsx @@ -0,0 +1,39 @@ +import { useState, useEffect } from 'react'; +import { Icon, faGithub } from '@rivet-gg/icons'; +import { cn } from '@rivet-gg/components'; + +interface GitHubStarsProps extends React.AnchorHTMLAttributes { + repo?: string; +} + +function formatNumber(num: number): string { + if (num >= 1000) { + return `${(num / 1000).toFixed(1)}k`; + } + return num.toString(); +} + +export async function GitHubStars({ repo = 'rivet-gg/rivet', className, ...props }: GitHubStarsProps) { + try { + const response = await fetch(`https://api.github.com/repos/${repo}`); + const data = await response.json(); + const { stargazers_count: stars } = data; + + return ( + + {stars ? `${formatNumber(stars)} Stars` : 'GitHub'} + + ); + } catch (err) { + console.error('Failed to fetch stars', err); + return null; + } +} \ No newline at end of file diff --git a/site/src/components/v2/FancyHeader.tsx b/site/src/components/v2/FancyHeader.tsx index 58000b6849..ba29de8471 100644 --- a/site/src/components/v2/FancyHeader.tsx +++ b/site/src/components/v2/FancyHeader.tsx @@ -10,6 +10,7 @@ import { faDiscord, faGithub, Icon } from '@rivet-gg/icons'; import { AnimatePresence, motion } from 'unframer'; import { HeaderPopupProductMenu } from '../HeaderPopupProductMenu'; import { HeaderPopupSolutionsMenu } from '../HeaderPopupSolutionsMenu'; +import { GitHubStars } from '@/components/GitHubStars'; type Subnav = false | 'product' | 'solutions'; @@ -19,7 +20,7 @@ interface FancyHeaderProps { mobileBreadcrumbs?: ReactNode; } -export function FancyHeader({ active, subnav }: FancyHeaderProps) { +export function FancyHeader({ active, subnav, mobileBreadcrumbs }: FancyHeaderProps) { const [isSubnavOpen, setIsSubnavOpen] = useState(false); const prev = useRef(false); @@ -72,16 +73,14 @@ export function FancyHeader({ active, subnav }: FancyHeaderProps) { } links={ - <> - +
+ - - - - + + - +
} mobileBreadcrumbs={} breadcrumbs={