Skip to content

Commit d3b1a93

Browse files
committed
Update Contributors.vue
1 parent 7fd9860 commit d3b1a93

File tree

3 files changed

+64
-56
lines changed

3 files changed

+64
-56
lines changed

.vitepress/get-contributors.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,29 @@
22
const fs = require('fs')
33
const path = require('path')
44

5-
const repo = process.argv[2]
6-
const file = process.argv[3] ?? '.vitepress/contributors.json'
7-
console.log(`get-contributors - repo: ${repo} - file: ${file}`)
8-
9-
if (!repo || !file) {
10-
console.error('Usage: npm run get-contributors user/repo')
11-
process.exit(1)
12-
}
5+
;(async () => {
6+
const repo = process.argv[2]
7+
const file = process.argv[3] ?? '.vitepress/contributors.json'
8+
console.log(`get-contributors - repo: ${repo} - file: ${file}`)
9+
10+
if (!repo || !file) {
11+
console.error('Usage: node get-contributors.js user/repo [contributors.json]')
12+
process.exit(1)
13+
}
1314

14-
fs.mkdirSync(path.dirname(file), { recursive: true })
15+
fs.mkdirSync(path.dirname(file), { recursive: true })
1516

16-
getAllContributors(repo)
17-
.then((data) => {
18-
// console.log('data:', data)
19-
fs.writeFileSync(file, JSON.stringify(data), 'utf8')
20-
})
21-
.catch((e) => {
22-
console.error(e)
23-
fs.writeFileSync(file, JSON.stringify([]), 'utf8')
24-
})
17+
let data = []
18+
try {
19+
data = await githubContributors(repo)
20+
} catch (e) {
21+
console.warn(e)
22+
}
23+
console.log(`get-contributors - contributors: ${data.length}`)
24+
fs.writeFileSync(file, JSON.stringify(data), 'utf8')
25+
})()
2526

26-
async function getAllContributors(repo) {
27+
async function githubContributors(repo) {
2728
let results = []
2829
let page = 1
2930

@@ -32,6 +33,7 @@ async function getAllContributors(repo) {
3233
const data = { headers: { Accept: 'application/vnd.github+json' } }
3334

3435
const response = await fetch(url, data)
36+
// console.log('response:', response)
3537
if (!response.ok) break
3638

3739
const contributors = await response.json()
Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,62 @@
11
<script setup>
22
import contributors from '../../contributors.json'
33
// console.debug('%c Contributors', 'color: Cyan', 'contributors:', contributors)
4-
const imageStyle = {}
4+
55
const props = defineProps({
6-
size: { type: String, default: null },
6+
size: { type: String, default: '64' },
7+
margin: { type: String, default: null },
8+
heading: { type: String, default: null },
79
})
8-
if (props.size) {
9-
imageStyle.height = props.size
10-
imageStyle.width = props.size
11-
}
10+
11+
const outerStyle = { margin: props.margin }
12+
console.log('outerStyle:', outerStyle)
13+
const imageStyle = { width: `${props.size}px`, height: `${props.size}px` }
14+
console.log('imageStyle:', imageStyle)
1215
</script>
1316

1417
<template>
15-
<div class="contributors">
16-
<a
17-
v-for="{ login, avatar_url } of contributors"
18-
:key="login"
19-
:aria-label="`${login} on GitHub`"
20-
:href="`https://github.com/${login}`"
21-
target="_blank"
22-
rel="noopener noreferrer"
23-
>
24-
<img :alt="login" :src="avatar_url" :style="imageStyle" loading="lazy" />
25-
</a>
18+
<div class="vp-contributors" :style="outerStyle">
19+
<div class="vp-contributors-heading" v-if="props.heading">{{ props.heading }}</div>
20+
<div class="vp-contributors-images">
21+
<a
22+
v-for="{ login, avatar_url } of contributors"
23+
:key="login"
24+
:aria-label="`${login} on GitHub`"
25+
:href="`https://github.com/${login}`"
26+
target="_blank"
27+
rel="noopener noreferrer"
28+
>
29+
<img
30+
:alt="login"
31+
:src="avatar_url"
32+
:width="props.size"
33+
:height="props.size"
34+
:style="imageStyle"
35+
loading="lazy"
36+
/>
37+
</a>
38+
</div>
2639
</div>
2740
</template>
2841

2942
<style scoped>
30-
div.contributors {
43+
div.vp-contributors-heading {
44+
font-size: 32px;
45+
text-align: center;
46+
margin-bottom: 36px;
47+
}
48+
49+
div.vp-contributors-images {
3150
display: flex;
3251
flex-wrap: wrap;
3352
gap: 0.8rem;
3453
justify-content: center;
3554
align-items: center;
3655
}
3756
38-
.contributors img {
57+
.vp-contributors img {
3958
margin: 0;
4059
border-radius: 50%;
41-
width: 4rem;
42-
height: 4rem;
4360
/* styles for img:hover transform */
4461
display: inline-block;
4562
vertical-align: middle;
@@ -51,7 +68,7 @@ div.contributors {
5168
transition-property: transform;
5269
}
5370
54-
.contributors img:hover {
71+
.vp-contributors img:hover {
5572
transform: scale(1.08);
5673
}
5774
</style>

docs/index.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ features:
4242
div.badges {
4343
margin-top: 80px;
4444
}
45-
45+
.badges > hr {
46+
margin-bottom: 24px;
47+
}
4648
.badges > p {
4749
text-align: center;
4850
}
49-
5051
.badges img {
5152
display: inline-block;
5253
vertical-align: middle;
@@ -60,16 +61,6 @@ div.badges {
6061
.badges img:hover {
6162
transform: scale(1.05);
6263
}
63-
64-
.contributors {
65-
margin-top: 20px;
66-
}
67-
68-
.contributors-heading {
69-
margin-top: 40px;
70-
text-align: center;
71-
font-size: 1.5em;
72-
}
7364
</style>
7465

7566
<div class="badges">
@@ -97,6 +88,4 @@ div.badges {
9788

9889
</div>
9990

100-
<div class="contributors-heading">Contributors</div>
101-
102-
<Contributors />
91+
<Contributors heading="Contributors" margin="36px 0 96px" />

0 commit comments

Comments
 (0)