Files
cursor-byok/apps/docs/lib/github.ts
T
leookun eca063e424 feat(docs): enhance documentation site with internationalization and layout updates
- Updated the demo API to support locale-based content rendering.
- Refactored the main layout to accommodate language-specific metadata and routing.
- Introduced new components for blog and documentation pages, ensuring proper language handling.
- Added styles for improved UI consistency across different sections.
- Removed deprecated layout files and streamlined the structure for better maintainability.
2026-08-28 00:35:31 +08:00

40 lines
1.1 KiB
TypeScript

import { gitConfig } from './shared';
export type RepoStats = {
stars: number | null;
version: string | null;
};
async function fetchJson(url: string): Promise<Record<string, unknown> | null> {
try {
const res = await fetch(url, {
headers: { Accept: 'application/vnd.github+json' },
next: { revalidate: 3600 },
});
if (!res.ok) return null;
return (await res.json()) as Record<string, unknown>;
} catch {
return null;
}
}
export async function getRepoStats(): Promise<RepoStats> {
const base = `https://api.github.com/repos/${gitConfig.user}/${gitConfig.repo}`;
const [repo, release] = await Promise.all([
fetchJson(base),
fetchJson(`${base}/releases/latest`),
]);
return {
stars: typeof repo?.stargazers_count === 'number' ? repo.stargazers_count : null,
version: typeof release?.tag_name === 'string' ? release.tag_name : null,
};
}
export function formatStars(stars: number): string {
return new Intl.NumberFormat('en', {
notation: 'compact',
maximumFractionDigits: 1,
}).format(stars);
}