From 3ca050ba1582cb0dd4ce8024ca79775321345959 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miku=E3=81=AE=E9=AC=86?= Date: Mon, 4 Nov 2024 10:53:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B4=A1=E7=8C=AE=E8=80=85=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=A4=9A=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E8=B4=A1=E7=8C=AE=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 首页贡献者头像获取多仓库贡献者,自动合并重复贡献者,按照总贡献排序,可自定义屏蔽部分Bot --- app/(home)/page.tsx | 22 +++++++++-- app/components/contributor-count.tsx | 56 +++++++++++++++++++--------- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/app/(home)/page.tsx b/app/(home)/page.tsx index 1565135..a92ece8 100644 --- a/app/(home)/page.tsx +++ b/app/(home)/page.tsx @@ -373,7 +373,7 @@ function Feedback(): React.ReactElement {

- "用了一年多的 Mix Space,最让我觉得舒服的一点是别人如果要和我换友链,可以自助提交,我只需要点个通过就可以了,也借此交到了很多的朋友,光这一点我觉得就很不错了" + "用了一年多的 Mix Space,最让我觉得舒服的一点是别人如果要和我换友链,可以自助提交,我只需要点个通过就可以了,也借此交到了很多的朋友,光这一点我觉���就很不错了"

diff --git a/app/components/contributor-count.tsx b/app/components/contributor-count.tsx index 3483d14..a9dc414 100644 --- a/app/components/contributor-count.tsx +++ b/app/components/contributor-count.tsx @@ -1,35 +1,62 @@ import type { HTMLAttributes } from 'react'; import Image from 'next/image'; -import { cn } from '@/utils/cn'; import { fetchContributors } from '@/utils/get-contributors'; export interface ContributorCounterProps extends HTMLAttributes { - repoOwner: string; - repoName: string; + repos: Array<{ + owner: string; + name: string; + }>; displayCount?: number; + excludeUsers?: string[]; } export default async function ContributorCounter({ - repoOwner, - repoName, + repos, displayCount = 20, + excludeUsers = [], ...props }: ContributorCounterProps): Promise { - const contributors = await fetchContributors(repoOwner, repoName); - const topContributors = contributors - .filter((contributor) => contributor.login !== repoOwner) - .slice(0, displayCount); + + const contributorsPromises = repos.map(repo => + fetchContributors(repo.owner, repo.name) + ); + + const allContributorsList = await Promise.all(contributorsPromises); + + + const mergedContributors = new Map(); + + allContributorsList.flat().forEach(contributor => { + if (excludeUsers.includes(contributor.login)) { + return; + } + + if(mergedContributors.has(contributor.login)) { + const existing = mergedContributors.get(contributor.login)!; + existing.contributions += contributor.contributions; + } else { + mergedContributors.set(contributor.login, contributor); + } + }); + + const sortedContributors = Array.from(mergedContributors.values()) + .sort((a, b) => b.contributions - a.contributions); return (
- {topContributors.map((contributor, i) => ( + {sortedContributors.map((contributor) => (
@@ -45,14 +72,9 @@ export default async function ContributorCounter({
))} - {displayCount < contributors.length && ( -
- +{contributors.length - displayCount} -
- )}
- 感谢这些为文档做出贡献的优秀贡献者 + 感谢这些为 Mix Space 开源社区做出贡献的优秀开发者
);