diff --git a/src/admin/github/GitHubForkStatusBadgeClient.tsx b/src/admin/github/GitHubForkStatusBadgeClient.tsx index c51a4c32..66f92c3d 100644 --- a/src/admin/github/GitHubForkStatusBadgeClient.tsx +++ b/src/admin/github/GitHubForkStatusBadgeClient.tsx @@ -10,7 +10,7 @@ export default function GitHubForkStatusBadgeClient({ tooltip, }: { label?: ReactNode - style?: 'success' | 'warning' | 'mono' + style?: 'success' | 'warning' | 'error' | 'mono' tooltip?: ReactNode }) { const classNameForStyle = () => { @@ -22,11 +22,17 @@ export default function GitHubForkStatusBadgeClient({ 'border-green-300/40 dark:border-green-900/50', ); case 'warning': return clsx( - 'text-amber-800/90 hover:text-amber-700', + 'text-amber-800/90 hover:text-amber-800/90', 'dark:text-amber-400 dark:hover:text-amber-400', 'bg-amber-100/40 dark:bg-amber-900/25', 'border-amber-300/40 dark:border-amber-900/50', ); + case 'error': return clsx( + 'text-red-700/90 hover:text-red-700/90', + 'dark:text-red-400 dark:hover:text-red-400', + 'bg-red-100/20 dark:bg-red-900/25', + 'border-red-300/40 dark:border-red-900/50', + ); default: return clsx( 'text-main', 'bg-white dark:bg-transparent', diff --git a/src/admin/github/GitHubForkStatusBadgeServer.tsx b/src/admin/github/GitHubForkStatusBadgeServer.tsx index 8299ce75..5b7657fe 100644 --- a/src/admin/github/GitHubForkStatusBadgeServer.tsx +++ b/src/admin/github/GitHubForkStatusBadgeServer.tsx @@ -20,28 +20,43 @@ export default async function GitHubForkStatusBadgeServer() { isBehind, label, description, + didError, } = await getGitHubMetaWithFallback({ owner, repo, branch, commit }); + const repoLink = (text: string) => + + {text} + ; + + const isBehindContent = <> + {' '} + {repoLink('Sync on GitHub')} for latest updates. + ; + + const didErrorContent = <> + {' '} + Could not connect to {repoLink('GitHub')}. + ; + return isForkedFromBase || isBaseRepo ? {description} - {isBehind && <> - {' '} - - Sync on GitHub - - {' '} - for latest updates. - } + {didError + ? didErrorContent + : isBehind + ? isBehindContent + : null} , - style: isBehind === undefined || isBehind ? 'warning' : 'mono', + style: didError || isBehind === undefined || isBehind + ? 'warning' + : 'mono', }} /> : null; } diff --git a/src/admin/github/index.ts b/src/admin/github/index.ts index 9213f0ae..b36c79cc 100644 --- a/src/admin/github/index.ts +++ b/src/admin/github/index.ts @@ -5,14 +5,13 @@ import { } from '@/site/config'; const DEFAULT_BRANCH = 'main'; - const FALLBACK_TEXT = 'Unknown'; +const CACHE_GITHUB_REQUESTS = false; // Cache all results for 2 minutes to avoid rate limiting // GitHub API requests limited to 60 requests per hour -const FETCH_CONFIG: RequestInit = { - next: { revalidate: 120 }, -}; +const FETCH_CONFIG: RequestInit = CACHE_GITHUB_REQUESTS + ? { next: { revalidate: 120 } } : {}; interface RepoParams { owner?: string @@ -152,6 +151,7 @@ const getGitHubMeta = async (params: RepoParams) => { isBehind, label, description, + didError: false, }; }; @@ -166,6 +166,7 @@ export const getGitHubMetaWithFallback = (params: RepoParams) => behindBy: undefined, isBehind: undefined, label: FALLBACK_TEXT, - description: FALLBACK_TEXT, + description: 'Could not connect to GitHub.', + didError: true, }; });