Skip to content

Commit de272b5

Browse files
authored
refactor(github): extract language color map (JhaSourav07#572)
## Description Fixes JhaSourav07#296 Extracted the language color mapping from `lib/github.ts` into a dedicated `lib/svg/languageColors.ts` module to separate presentation data from data-fetching logic. Updated `lib/github.ts` to import and use `LANGUAGE_COLORS`. ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable (refactoring change) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [ ] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). - [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). - [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). - [ ] I have updated `README.md` if I added a new theme or URL parameter. - [x] I have started the repo. - [x] I have made sure that i have only one commit to merge in this PR. - [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). - [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 9449330 + b70b631 commit de272b5

2 files changed

Lines changed: 28 additions & 30 deletions

File tree

lib/github.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import type { ContributionCalendar } from '../types';
44
import { calculateStreak } from './calculate';
55
import { TTLCache } from './cache';
6+
import { LANGUAGE_COLORS } from './svg/languageColors';
67

78
interface GitHubRepo {
89
stargazers_count: number;
@@ -459,41 +460,12 @@ export async function getFullDashboardData(username: string, options: FetchOptio
459460
}
460461
});
461462

462-
// Fixed color mapping for common languages to avoid random colors
463-
const languageColors: Record<string, string> = {
464-
TypeScript: '#3178c6',
465-
JavaScript: '#f1e05a',
466-
Python: '#3572A5',
467-
Java: '#b07219',
468-
'C++': '#f34b7d',
469-
HTML: '#e34c26',
470-
CSS: '#563d7c',
471-
Go: '#00ADD8',
472-
Rust: '#dea584',
473-
474-
C: '#555555',
475-
'C#': '#178600',
476-
PHP: '#4F5D95',
477-
Ruby: '#701516',
478-
Swift: '#F05138',
479-
Kotlin: '#A97BFF',
480-
Dart: '#00B4AB',
481-
Lua: '#000080',
482-
R: '#198CE7',
483-
Scala: '#c22d40',
484-
Perl: '#0298c3',
485-
Haskell: '#5e5086',
486-
Elixir: '#6e4a7e',
487-
Vue: '#41b883',
488-
Svelte: '#ff3e00',
489-
};
490-
491463
const totalLangs = Object.values(langCounts).reduce((a, b) => a + b, 0);
492464
const languages = Object.entries(langCounts)
493465
.map(([name, count]) => ({
494466
name,
495467
percentage: Math.round((count / totalLangs) * 100),
496-
color: languageColors[name] || '#a855f7', // fallback purple
468+
color: LANGUAGE_COLORS[name] || '#a855f7', // fallback purple
497469
}))
498470
.sort((a, b) => b.percentage - a.percentage)
499471
.slice(0, 5); // top 5

lib/svg/languageColors.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const LANGUAGE_COLORS: Record<string, string> = {
2+
TypeScript: '#3178c6',
3+
JavaScript: '#f1e05a',
4+
Python: '#3572A5',
5+
Java: '#b07219',
6+
'C++': '#f34b7d',
7+
HTML: '#e34c26',
8+
CSS: '#563d7c',
9+
Go: '#00ADD8',
10+
Rust: '#dea584',
11+
C: '#555555',
12+
'C#': '#178600',
13+
PHP: '#4F5D95',
14+
Ruby: '#701516',
15+
Swift: '#F05138',
16+
Kotlin: '#A97BFF',
17+
Dart: '#00B4AB',
18+
Lua: '#000080',
19+
R: '#198CE7',
20+
Scala: '#c22d40',
21+
Perl: '#0298c3',
22+
Haskell: '#5e5086',
23+
Elixir: '#6e4a7e',
24+
Vue: '#41b883',
25+
Svelte: '#ff3e00',
26+
};

0 commit comments

Comments
 (0)