Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show github stars #1817

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions site/src/components/GitHubStars.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useState, useEffect } from 'react';
import { Icon, faGithub } from '@rivet-gg/icons';

interface GitHubStarsProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
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', ...props }: GitHubStarsProps) {
try {
const response = await fetch(`https://api.github.com/repos/${repo}`);
const data = await response.json();
const { stargazers_count: stars } = data;
return (
<a
href={`https://github.com/${repo}`}
target='_blank'
rel='noreferrer'
{...props}>
<Icon icon={faGithub} /> <span className="hidden md:inline">{stars ? `${formatNumber(stars)} Stars` : 'GitHub'}</span>
</a>
);
} catch (err) {
console.error('Failed to fetch stars', err);
return null;
}
}
5 changes: 2 additions & 3 deletions site/src/components/v2/FancyHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -79,9 +80,7 @@ export function FancyHeader({ active, subnav }: FancyHeaderProps) {
</Link>
</RivetHeader.NavItem>
<RivetHeader.NavItem asChild className='p-2'>
<Link href='https://github.com/rivet-gg/rivet' target='_blank' className='text-white/90'>
<Icon icon={faGithub} className='drop-shadow-md' />
</Link>
<GitHubStars className='text-white/90 hover:text-white transition-colors' />
</RivetHeader.NavItem>
<Button
variant='secondary'
Expand Down