1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-28 19:49:50 +02:00

Fix opensource star count shoing NaN

This commit is contained in:
Kamran Ahmed
2023-01-05 04:27:50 +04:00
parent 58315932be
commit 313e584711
2 changed files with 18 additions and 5 deletions

View File

@@ -30,6 +30,6 @@ export default defineConfig({
filter: shouldIndexPage,
serialize: serializeSitemap,
}),
critters(),
// critters(),
],
});

View File

@@ -2,20 +2,33 @@ const formatter = Intl.NumberFormat('en-US', {
notation: 'compact',
});
let starCount: number | undefined = undefined;
export async function countStars(
repo = 'kamranahmedse/developer-roadmap'
): Promise<number> {
const repoData = await fetch(`https://api.github.com/repos/${repo}`);
const json = await repoData.json();
if (starCount) {
return starCount;
}
return json.stargazers_count * 1;
try {
const repoData = await fetch(`https://api.github.com/repos/${repo}`);
const json = await repoData.json();
starCount = json.stargazers_count * 1;
} catch (e) {
console.log('Failed to fetch stars', e);
starCount = 224000;
}
return starCount;
}
export async function getFormattedStars(
repo = 'kamranahmedse/developer-roadmap'
): Promise<string> {
if (import.meta.env.DEV) {
return '223k';
return '224k';
}
const stars = await countStars(repo);