Skip to content

Commit b70b631

Browse files
committed
refactor(github): extract language color map
1 parent e15a46a commit b70b631

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)