1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-10 19:26:03 +02:00

Refactor github stats

This commit is contained in:
Kamran Ahmed
2024-08-19 12:36:28 +01:00
parent bcc456d3d0
commit c6a4bff63e
3 changed files with 13 additions and 21 deletions

View File

@@ -6,7 +6,6 @@ import satori from 'satori';
import sharp from 'sharp'; import sharp from 'sharp';
import imageSize from 'image-size'; import imageSize from 'image-size';
import { Resvg } from '@resvg/resvg-js'; import { Resvg } from '@resvg/resvg-js';
import { getRepositoryRank } from '../src/lib/github';
const ALL_ROADMAP_DIR = path.join(process.cwd(), '/src/data/roadmaps'); const ALL_ROADMAP_DIR = path.join(process.cwd(), '/src/data/roadmaps');
const ALL_BEST_PRACTICE_DIR = path.join( const ALL_BEST_PRACTICE_DIR = path.join(
@@ -29,11 +28,6 @@ const alreadyGeneratedImages = await fs.readdir(
}, },
); );
async function updateRank() {
const repoRank = await getRepositoryRank('kamranahmedse/developer-roadmap');
document.getElementById('repo-rank').innerText = `${repoRank} most starred GitHub project`;
}
async function getAllRoadmaps() { async function getAllRoadmaps() {
const allRoadmapDirNames = await fs.readdir(ALL_ROADMAP_DIR); const allRoadmapDirNames = await fs.readdir(ALL_ROADMAP_DIR);
@@ -148,8 +142,6 @@ async function getAllBestPracticeImageIds() {
} }
async function generateResourceOpenGraph() { async function generateResourceOpenGraph() {
await updateRank();
const allRoadmaps = (await getAllRoadmaps()).filter( const allRoadmaps = (await getAllRoadmaps()).filter(
(roadmap) => !alreadyGeneratedImages.includes(`roadmaps/${roadmap.id}.png`), (roadmap) => !alreadyGeneratedImages.includes(`roadmaps/${roadmap.id}.png`),
); );
@@ -379,8 +371,8 @@ function getRoadmapDefaultTemplate({ title, description }) {
/> />
</svg> </svg>
</div> </div>
<div tw="text-[30px] flex leading-[30px]" id="repo-rank"> <div tw="text-[30px] flex leading-[30px]">
Loading... 7th most starred GitHub project
</div> </div>
</div> </div>
<div tw="flex items-center mt-2.5"> <div tw="flex items-center mt-2.5">

View File

@@ -1,10 +1,11 @@
--- ---
import { getFormattedStars, getRepositoryRank } from '../lib/github'; import { getFormattedStars, getRepositoryRank } from '../lib/github';
import Icon from './AstroIcon.astro';
import { getDiscordInfo } from '../lib/discord'; import { getDiscordInfo } from '../lib/discord';
import OpenSourceStat from './OpenSourceStat.astro'; import OpenSourceStat from './OpenSourceStat.astro';
const repoName = 'kamranahmedse/developer-roadmap'; const repoName = 'kamranahmedse/developer-roadmap';
const starCount = await getFormattedStars(repoName); const starCount = await getFormattedStars(repoName);
const repoRank = await getRepositoryRank(repoName); const repoRank = await getRepositoryRank(repoName);
const discordInfo = await getDiscordInfo(); const discordInfo = await getDiscordInfo();
@@ -25,11 +26,12 @@ const discordInfo = await getDiscordInfo();
<div <div
class='mt-5 grid grid-cols-1 justify-between gap-2 divide-x-0 sm:my-11 sm:grid-cols-3 sm:gap-0 sm:divide-x mb-4 sm:mb-0' class='mt-5 grid grid-cols-1 justify-between gap-2 divide-x-0 sm:my-11 sm:grid-cols-3 sm:gap-0 sm:divide-x mb-4 sm:mb-0'
> >
<OpenSourceStat text='GitHub Stars' value={starCount} /> <OpenSourceStat text='GitHub Stars' value={starCount} secondaryValue={repoRank} />
<OpenSourceStat text='Registered Users' value={'+1M'} /> <OpenSourceStat text='Registered Users' value={'+1M'} secondaryValue="+90k" />
<OpenSourceStat <OpenSourceStat
text='Discord Members' text='Discord Members'
value={discordInfo.totalFormatted} value={discordInfo.totalFormatted}
secondaryValue="+1.5k"
/> />
</div> </div>
</div> </div>

View File

@@ -1,19 +1,17 @@
--- ---
import { ChevronUp } from 'lucide-react';
import Icon from './AstroIcon.astro'; import Icon from './AstroIcon.astro';
import { getRepositoryRank } from '../lib/github';
export interface Props { export interface Props {
secondaryValue?: string;
value: string; value: string;
text: string; text: string;
} }
const { value, text } = Astro.props; const { value, text, secondaryValue } = Astro.props;
const isGitHubStars = text.toLowerCase() === 'github stars'; const isGitHubStars = text.toLowerCase() === 'github stars';
const isRegistered = text.toLowerCase() === 'registered users'; const isRegistered = text.toLowerCase() === 'registered users';
const isDiscordMembers = text.toLowerCase() === 'discord members'; const isDiscordMembers = text.toLowerCase() === 'discord members';
const repoRank = await getRepositoryRank('kamranahmedse/developer-roadmap');
--- ---
<div <div
@@ -22,7 +20,7 @@ const repoRank = await getRepositoryRank('kamranahmedse/developer-roadmap');
{ {
isGitHubStars && ( isGitHubStars && (
<p class='flex items-center text-sm text-blue-500 sm:flex'> <p class='flex items-center text-sm text-blue-500 sm:flex'>
<span class='rounded-md bg-blue-500 px-1 text-white'>Rank {repoRank}</span> <span class='rounded-md bg-blue-500 px-1 text-white'>Rank {secondaryValue}</span>
&nbsp;out of 28M! &nbsp;out of 28M!
</p> </p>
) )
@@ -31,7 +29,7 @@ const repoRank = await getRepositoryRank('kamranahmedse/developer-roadmap');
{ {
isRegistered && ( isRegistered && (
<p class='flex items-center text-sm text-blue-500 sm:flex'> <p class='flex items-center text-sm text-blue-500 sm:flex'>
<span class='mr-1.5 rounded-md bg-blue-500 px-1 text-white'>+75k</span> <span class='mr-1.5 rounded-md bg-blue-500 px-1 text-white'>{secondaryValue}</span>
every month every month
</p> </p>
) )
@@ -40,7 +38,7 @@ const repoRank = await getRepositoryRank('kamranahmedse/developer-roadmap');
{ {
isDiscordMembers && ( isDiscordMembers && (
<p class='flex items-center text-sm text-blue-500 sm:flex'> <p class='flex items-center text-sm text-blue-500 sm:flex'>
<span class='mr-1.5 rounded-md bg-blue-500 px-1 text-white'>+1.5k</span> <span class='mr-1.5 rounded-md bg-blue-500 px-1 text-white'>{secondaryValue}</span>
every month every month
</p> </p>
) )