diff --git a/web/src/components/things/GitHubDetailedInfo.astro b/web/src/components/things/GitHubDetailedInfo.astro new file mode 100644 index 0000000..9b39a4d --- /dev/null +++ b/web/src/components/things/GitHubDetailedInfo.astro @@ -0,0 +1,282 @@ +--- +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': '#F18E33', + 'Objective-C': '#438eff', + 'Ruby': '#701516', + 'Go': '#375eab', + 'PHP': '#4F5D95', + 'Java': '#b07219', + 'Scala': '#DC322F', + 'Makefile': '#427819', + 'Perl': '#0298c3', + 'Lua': '#000080', + 'Vue': '#2c3e50', + 'HTML': '#e44b23', + 'Swift': '#ffac45', + 'C': '#555555', + 'C#': '#097c01', + 'Clojure': '#db5855', + 'Rust': '#dea584', + 'Assembly': '#6E4C13', + 'Arduino': '#bd79d1', + 'C Sharp': '#178600', + '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': '#f34b7d', + }; + + // 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 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} +

License

+

{gitHubData.info.license}

+

Created

+

{formatDate(gitHubData.info.createdAt)}

+

Last Updated

+

{formatDate(gitHubData.info.updatedAt)}

+ { gitHubData.versions.length > 0 && ( +

Latest version

+

+ {gitHubData.versions[0].name} + +

+ )} +

Primary Language

+

{gitHubData.info.language}

+

Size

+

{formatBigNumber(gitHubData.info.size)} KB

+

Stars

+

{formatBigNumber(gitHubData.info.scarCount)}

+

Forks

+

{formatBigNumber(gitHubData.info.forksCount)}

+

Watchers

+

{formatBigNumber(gitHubData.info.watchersCount)}

+ +
+
+

Language Usage

+ Language Usage +

Star History

+ Star History +
+
+
+

Top Contributors

+
    + {gitHubData.contributors.map((contributor) => ( +
  • + + @{contributor.username} ({contributor.contributions}) +
  • + ))} +
+
+
+

Recent Commits

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

    {commit.message}

    +
  • + ))} +
+
+
+
+ +