11<template >
2- <div v-if =" hasContributors" >
3- <h2 class =" title" >Contributors</h2 >
4- <p class =" description" >Your contributions matter. Here's to everyone who's helped bring this to life.</p >
5- <div class =" contributors-list" >
6- <div class =" contributor" v-for =" contributor in contributors" :key =" contributor.login" >
7- <img
8- class =" contributor__avatar"
9- :src =" contributor.avatar_url"
10- :alt =" 'The avatar used by ' + contributor.login"
11- width =" 80"
12- height =" 80"
13- />
14- <a class =" contributor__name" :href =" contributor.html_url" >{{ contributor.login }} <OutboundLink /></a >
15- </div >
16- </div >
2+ <div v-if =" hasContributors" >
3+ <h2 class =" title" >Contributors</h2 >
4+ <p class =" description" >Your contributions matter. Here's to everyone who's helped bring this to life.</p >
5+ <div class =" contributors-list" >
6+ <div class =" contributor" v-for =" contributor in contributors" :key =" contributor.login" >
7+ <img
8+ class =" contributor__avatar"
9+ :src =" contributor.avatar_url"
10+ :alt =" 'The avatar used by ' + contributor.login"
11+ width =" 80"
12+ height =" 80"
13+ />
14+ <a class =" contributor__name" :href =" contributor.html_url" >{{ contributor.login }} <OutboundLink /></a >
1715 </div >
18- </template >
19-
20-
21-
22-
23- <script lang="ts">
24- import { computed , defineComponent , ref } from ' vue'
25-
26- interface Contributor {
27- login: string
28- avatar_url: string
29- html_url: string
30- contributions: number
31- type: string
32- }
33-
34- export default defineComponent ({
35- props: {
36- repo: {
37- type: String ,
38- required: true
16+ </div >
17+ </div >
18+ </template >
19+
20+
21+
22+
23+ <script lang="ts">
24+ import { computed , defineComponent , ref } from ' vue'
25+
26+ interface Contributor {
27+ login: string
28+ avatar_url: string
29+ html_url: string
30+ contributions: number
31+ type: string
32+ }
33+
34+ export default defineComponent ({
35+ props: {
36+ repo: {
37+ type: String ,
38+ required: true
39+ }
40+ },
41+
42+ setup(props ) {
43+ const contributors = ref ([])
44+ const error = ref (null )
45+ const hasContributors = computed (() => !! contributors .value ?.length )
46+
47+ fetch (` https://api.github.com/repos/${props .repo }/contributors ` , {
48+ headers: {
49+ " Accept" : " application/vnd.github.v3+json"
3950 }
40- },
41-
42- setup(props ) {
43- const contributors = ref ([])
44- const error = ref (null )
45- const hasContributors = computed (() => !! contributors .value ?.length )
46-
47- fetch (` https://api.github.com/repos/${props .repo }/contributors ` , {
48- headers: {
49- " Accept" : " application/vnd.github.v3+json"
50- }
51+ })
52+ .then (res => res .json ())
53+ .then ((res : Contributor []) => res )
54+ .then (contributors => contributors .filter (c => c .type === " User" ))
55+ .then (users => {
56+ users .sort ((a , b ) => b .contributions - a .contributions )
57+ contributors .value = users
5158 })
52- .then (res => res .json ())
53- .then ((res : Contributor []) => res )
54- .then (contributors => contributors .filter (c => c .type === " User" ))
55- .then (users => {
56- users .sort ((a , b ) => b .contributions - a .contributions )
57- contributors .value = users
58- })
59- .catch (err => {
60- error .value = err
61- })
62-
63- return {
64- contributors ,
65- hasContributors ,
66- error
67- }
59+ .catch (err => {
60+ error .value = err
61+ })
62+
63+ return {
64+ contributors ,
65+ hasContributors ,
66+ error
6867 }
69- })
70- </script >
71-
72- <style scoped>
73- .contributors-list {
74- display : flex ;
75- flex-direction : row ;
76- justify-content : space-around ;
77- flex-wrap : wrap ;
78- }
79-
80- .contributor {
81- display : flex ;
82- flex-direction : column ;
83- align-content : center ;
84- justify-content : space-between ;
85- margin : 20px ;
86- }
87-
88- .contributor__avatar {
89- border-radius : 50% ;
90- display : inline-block ;
91- margin : 5px auto ;
92- }
93-
94- .contributor__name {
95- margin : 5px auto ;
96- }
97-
98- .title {
99- font-size : 28px ;
100- font-weight : 900 ;
101- margin-bottom : 20px ;
102- text-align : center ;
103- transition : color var (--vp-t-color );
104- color : var (--vp-c-text-1 );
105- }
106-
107- .description {
108- font-size : 18px ;
109- font-weight : 400 ;
110- margin-bottom : 20px ;
111- text-align : center ;
112- transition : color var (--vp-t-color );
113- color : var (--vp-c-text-1 );
11468 }
115- </style >
69+ })
70+ </script >
71+
72+ <style scoped>
73+ .contributors-list {
74+ display : flex ;
75+ flex-direction : row ;
76+ justify-content : space-around ;
77+ flex-wrap : wrap ;
78+ }
79+
80+ .contributor {
81+ display : flex ;
82+ flex-direction : column ;
83+ align-content : center ;
84+ justify-content : space-between ;
85+ margin : 20px ;
86+ }
87+
88+ .contributor__avatar {
89+ border-radius : 50% ;
90+ display : inline-block ;
91+ margin : 5px auto ;
92+ }
93+
94+ .contributor__name {
95+ margin : 5px auto ;
96+ }
97+
98+ .title {
99+ font-size : 28px ;
100+ font-weight : 900 ;
101+ margin-bottom : 20px ;
102+ text-align : center ;
103+ transition : color var (--vp-t-color );
104+ color : var (--vp-c-text-1 );
105+ }
106+
107+ .description {
108+ font-size : 18px ;
109+ font-weight : 400 ;
110+ margin-bottom : 20px ;
111+ text-align : center ;
112+ transition : color var (--vp-t-color );
113+ color : var (--vp-c-text-1 );
114+ }
115+ </style >
0 commit comments