Skip to content

Commit 37b5a3c

Browse files
committed
Replace the GitHub icon with a "Star" button
1 parent 2812d9f commit 37b5a3c

4 files changed

Lines changed: 59 additions & 4 deletions

File tree

app/layout.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '@fortawesome/fontawesome-svg-core/styles.css'
77
import 'nextra-theme-docs/style.css'
88
import '../styles/globals.css'
99
import { Fragment } from 'react'
10+
import GitHubStarButton from '../components/GitHubStarButton'
1011

1112
config.autoAddCss = false
1213

@@ -31,9 +32,11 @@ const navbar = (
3132
<DocsNavbar
3233
key="navbar"
3334
logo={<span className="logo"></span>}
34-
projectLink="https://github.com/FOSSBilling/FOSSBilling"
35+
projectLink={null}
3536
chatLink="https://fossbilling.org/discord"
36-
/>
37+
>
38+
<GitHubStarButton/>
39+
</DocsNavbar>
3740
)
3841

3942
export default async function RootLayout({ children }) {

components/DocsNavbar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ const DocsNavbar = ({
203203
)}
204204
<ClientNavbar className={alignLeft ? 'x:me-auto' : ''}>
205205
{projectLink && <Anchor href={projectLink}>{projectIcon}</Anchor>}
206-
{chatLink && <Anchor href={chatLink}>{chatIcon}</Anchor>}
207206
{children}
207+
{chatLink && <Anchor href={chatLink}>{chatIcon}</Anchor>}
208208
</ClientNavbar>
209209
</nav>
210210
</header>

components/GitHubStarButton.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { faStar } from '@fortawesome/free-solid-svg-icons'
2+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3+
import { GitHubIcon } from 'nextra/icons'
4+
import Link from 'next/link'
5+
6+
async function getStarCount() {
7+
try {
8+
const res = await fetch('https://api.github.com/repos/FOSSBilling/FOSSBilling', {
9+
next: { revalidate: 7200 } // Cache for 2 hours
10+
})
11+
12+
if (!res.ok) {
13+
throw new Error('Failed to fetch stars')
14+
}
15+
16+
const data = await res.json()
17+
return data.stargazers_count
18+
} catch (error) {
19+
console.error('Error fetching star count:', error)
20+
return null
21+
}
22+
}
23+
24+
function formatCompactNumber(number: number) {
25+
const formatter = Intl.NumberFormat("en", { notation: "compact" });
26+
return formatter.format(number);
27+
}
28+
29+
export default async function GitHubStarButton() {
30+
const stars = await getStarCount()
31+
32+
return (
33+
<Link
34+
href="https://github.com/FOSSBilling/FOSSBilling"
35+
target="_blank"
36+
className="group flex items-center gap-2 rounded-md bg-black/10 px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-black/20 dark:bg-white/10 dark:text-gray-200 dark:hover:bg-white/20"
37+
aria-label="Star FOSSBilling on GitHub"
38+
>
39+
<GitHubIcon className="h-4 w-4" />
40+
<span>Star</span>
41+
{stars !== null && (
42+
<>
43+
<div className="h-4 w-px bg-gray-300 dark:bg-gray-600" />
44+
<div className="flex items-center gap-1">
45+
<FontAwesomeIcon icon={faStar} className="h-3 w-3 text-yellow-500" />
46+
<span>{formatCompactNumber(stars)}</span>
47+
</div>
48+
</>
49+
)}
50+
</Link>
51+
)
52+
}

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
import "./.next/types/routes.d.ts";
3+
import "./.next/dev/types/routes.d.ts";
44

55
// NOTE: This file should not be edited
66
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

0 commit comments

Comments
 (0)