--- import type { GitHubStatsResponse } from '@utils/fetch-repo-info' import { formatDate, timeAgo } from '@utils/dates-n-stuff'; import FontAwesome from "@components/form/FontAwesome.svelte" interface Props { gitHubData: GitHubStatsResponse; repo: string; } const { gitHubData, repo } = Astro.props; function generateChartData(languages: Record): string { const colorMap: { [key: string]: string } = { 'TypeScript': '#2b7489', 'Objective-C++': '#6866fb', 'Jupyter Notebook': '#DA5B0B', 'Dart': '#00B4AB', 'Shell': '#89e051', 'Elixir': '#6e4a7e', 'Kotlin': '#7F52FF', 'Objective-C': '#438eff', 'Ruby': '#CC342D', 'Go': '#00ADD8', 'PHP': '#4F5D95', 'Java': '#b07219', 'Scala': '#DC322F', 'Makefile': '#427819', 'Perl': '#39457E', 'Lua': '#2C2D72', 'Vue': '#4FC08D', 'HTML': '#E34F26', 'Swift': '#F05138', 'C': '#A8B9CC', 'C#': '#097c01', 'Clojure': '#db5855', 'Rust': '#dea584', 'Assembly': '#6E4C13', 'Arduino': '#bd79d1', 'C Sharp': '#512BD4', 'CSS': '#563d7c', 'TeX': '#3D6117', 'OCaml': '#3be133', 'Pascal': '#b0ce4e', 'F#': '#b845fc', 'JavaScript': '#f1e05a', 'VimL': '#199f4b', 'R': '#198ce7', 'Erlang': '#B83998', 'Scheme': '#1e4aec', 'Python': '#3572A5', 'Common Lisp': '#3fb68b', 'Groovy': '#e69f56', 'Julia': '#a270ba', 'cpp': '#00599C', 'C++': '#00599C', 'Dockerfile': '#2496ED', 'SCSS': '#CC6699', }; // Arrays to hold the data, labels, and colors const data: number[] = []; const labels: string[] = []; const colors: string[] = []; // Default colors to use if the language is not in the colorMap const defaultColors = ['#ffdf60', '#5f53f4', '#28dffd', '#f45397']; let defaultColorIndex = 0; // Populate the data, labels, and colors arrays for (const [language, lines] of Object.entries(languages)) { data.push(lines); labels.push(language); // Assign a color from the colorMap if available; otherwise, use a default color if (colorMap[language]) { colors.push(colorMap[language]); } else { colors.push(defaultColors[defaultColorIndex % defaultColors.length]); defaultColorIndex++; } } // Construct the chart data object as a string const chartData = JSON.stringify({ type: 'doughnut', data: { datasets: [{ data: data, backgroundColor: colors, borderWidth: 0, label: 'Language Usage', }], labels: labels, }, options: { cutoutPercentage: 80, legend: { display: true, }, plugins: { datalabels: { display: false, }, }, aspectRatio: 1, maintainAspectRatio: false, }, }); // Encode the chart data for use in a URL return encodeURIComponent(chartData); } const formatBigNumber = (num: number): string => { if (!num) return 'None'; return num.toLocaleString(); }; const formatLicense = (spdx: string): string => { if (!spdx) return 'Unknown'; return spdx === 'NOASSERTION' ? 'Other' : spdx; }; const YEAR_MS = 365 * 24 * 60 * 60 * 1000; const isInactive = Date.now() - new Date(gitHubData.info.pushedAt).getTime() > YEAR_MS; const badges: { label: string; alert?: boolean }[] = []; if (gitHubData.info.isArchived) badges.push({ label: 'Archived', alert: true }); if (isInactive) badges.push({ label: 'Inactive', alert: true }); if (gitHubData.info.isFork && gitHubData.info.forkParent) badges.push({ label: `Fork of ${gitHubData.info.forkParent}` }); if (!gitHubData.info.license) badges.push({ label: 'No license' }); const languageChart = `https://quickchart.io/chart?c=${generateChartData(gitHubData.languages)}`; ---

Author

{gitHubData.info.ownerUsername}

Description

{gitHubData.info.description}

{gitHubData.info.topics.map((topic) => ( #{topic} ))}

Homepage

{gitHubData.info.homepage}

Repository

  • License {formatLicense(gitHubData.info.license)}
  • Created {formatDate(gitHubData.info.createdAt)}
  • Primary language {gitHubData.info.language}
  • Size {formatBigNumber(gitHubData.info.size)} KB
  • Stars {formatBigNumber(gitHubData.info.starCount)}
  • Forks {formatBigNumber(gitHubData.info.forksCount)}
  • Watchers {formatBigNumber(gitHubData.info.watchersCount)}

Language Usage

Language Usage

Project Health

{ badges.length > 0 && ( {badges.map((badge) => ( {badge.label} ))} )}
  • Last commit {timeAgo(gitHubData.info.pushedAt)}
  • Open issues {formatBigNumber(gitHubData.info.openIssues)}
  • { gitHubData.versions.length > 0 && (
  • Latest release {gitHubData.versions[0].name}
  • )}

Top Contributors

Recent Commits

    {gitHubData.commits.map((commit) => (
  • {commit.authorName} ({formatDate(commit.authorDate)})

    {commit.message}

  • ))}