1+ <script lang="ts" setup>
2+ import { ref , onMounted } from ' vue'
3+
4+ const contributors = ref <any []>([])
5+
6+ const fromRepo = (repo : string ) =>
7+ fetch (` https://api.github.com/repos/tweakphp/${repo }/contributors ` )
8+ .then ((res ) => res .json ())
9+ .catch (() => [])
10+
11+ const getContributors = async () => {
12+ const users = await Promise .all ([
13+ fromRepo (' tweakphp' ),
14+ fromRepo (' docs' ),
15+ fromRepo (' client' ),
16+ fromRepo (' .github' ),
17+ ])
18+
19+ contributors .value = users
20+ .reduce ((acc , data = []) => {
21+ if (! Array .isArray (data )) return acc
22+ return [... acc , ... data .filter (i => i .login )]
23+ }, [])
24+ .reduce ((acc , user ) => {
25+ const existingUser = acc .find (u => u .id === user .id )
26+ if (existingUser ) {
27+ existingUser .contributions += user .contributions
28+ return acc
29+ }
30+ return [... acc , {
31+ id: user .id ,
32+ username: user .login ,
33+ contributions: user .contributions ,
34+ avatar_url: user .avatar_url
35+ }]
36+ }, [])
37+ }
38+
39+ onMounted (() => {
40+ getContributors ()
41+ })
42+ </script >
43+
44+ <template >
45+ <div class =" text-lg text-center leading-7 my-10 px-5" >
46+ <div class =" flex flex-wrap gap-2" >
47+ <a
48+ v-for =" contributor of contributors"
49+ :key =" contributor.id"
50+ v-tooltip =" contributor.username"
51+ :href =" `https://github.com/${contributor.username}`"
52+ :aria-label =" contributor.username"
53+ rel =" noopener noreferrer"
54+ target =" _blank"
55+ >
56+ <img
57+ :src =" contributor.avatar_url"
58+ :alt =" contributor.username"
59+ :aria-label =" contributor.username"
60+ loading =" lazy"
61+ width =" 50"
62+ height =" 50"
63+ class =" w-15 h-15 min-w-15 min-h-15 !rounded-full"
64+ />
65+ </a >
66+ </div >
67+ </div >
68+ </template >
0 commit comments