Skip to content

Commit 7fd9860

Browse files
authored
Add Contributors.vue (#2)
1 parent 0feea78 commit 7fd9860

File tree

7 files changed

+140
-2
lines changed

7 files changed

+140
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
build/
66
node_modules/
77
.vitepress/cache
8+
.vitepress/contributors.json

.vitepress/get-contributors.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs')
3+
const path = require('path')
4+
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+
}
13+
14+
fs.mkdirSync(path.dirname(file), { recursive: true })
15+
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+
})
25+
26+
async function getAllContributors(repo) {
27+
let results = []
28+
let page = 1
29+
30+
while (true) {
31+
const url = `https://api.github.com/repos/${repo}/contributors?per_page=100&page=${page}`
32+
const data = { headers: { Accept: 'application/vnd.github+json' } }
33+
34+
const response = await fetch(url, data)
35+
if (!response.ok) break
36+
37+
const contributors = await response.json()
38+
// console.log('contributors:', contributors)
39+
if (!contributors.length) break
40+
41+
const filtered = contributors
42+
.filter((c) => c.type === 'User')
43+
.map((c) => ({
44+
login: c.login,
45+
avatar_url: c.avatar_url,
46+
contributions: c.contributions,
47+
}))
48+
// console.log('filtered:', filtered)
49+
50+
results.push(...filtered)
51+
page++
52+
await new Promise((resolve) => setTimeout(resolve, 250))
53+
}
54+
55+
return results
56+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<script setup>
2+
import contributors from '../../contributors.json'
3+
// console.debug('%c Contributors', 'color: Cyan', 'contributors:', contributors)
4+
const imageStyle = {}
5+
const props = defineProps({
6+
size: { type: String, default: null },
7+
})
8+
if (props.size) {
9+
imageStyle.height = props.size
10+
imageStyle.width = props.size
11+
}
12+
</script>
13+
14+
<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>
26+
</div>
27+
</template>
28+
29+
<style scoped>
30+
div.contributors {
31+
display: flex;
32+
flex-wrap: wrap;
33+
gap: 0.8rem;
34+
justify-content: center;
35+
align-items: center;
36+
}
37+
38+
.contributors img {
39+
margin: 0;
40+
border-radius: 50%;
41+
width: 4rem;
42+
height: 4rem;
43+
/* styles for img:hover transform */
44+
display: inline-block;
45+
vertical-align: middle;
46+
transform: translateZ(0);
47+
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
48+
backface-visibility: hidden;
49+
-moz-osx-font-smoothing: grayscale;
50+
transition-duration: 0.3s;
51+
transition-property: transform;
52+
}
53+
54+
.contributors img:hover {
55+
transform: scale(1.08);
56+
}
57+
</style>

.vitepress/theme/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import DefaultTheme from 'vitepress/theme'
22
import './custom.css'
33
import 'virtual:group-icons.css'
44

5+
import Contributors from './components/Contributors.vue'
56
import YouTubeEmbed from './components/YouTubeEmbed.vue'
67

78
// noinspection JSUnusedGlobalSymbols
89
export default {
910
...DefaultTheme,
1011

1112
enhanceApp({ app }) {
13+
app.component('Contributors', Contributors)
1214
app.component('YouTubeEmbed', YouTubeEmbed)
1315
},
1416
}

docs/index.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ features:
3939
---
4040

4141
<style>
42-
.badges > p {
42+
div.badges {
4343
margin-top: 80px;
44+
}
45+
46+
.badges > p {
4447
text-align: center;
4548
}
4649

@@ -57,10 +60,22 @@ features:
5760
.badges img:hover {
5861
transform: scale(1.05);
5962
}
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+
}
6073
</style>
6174

6275
<div class="badges">
6376

77+
---
78+
6479
[![GitHub Tag Major](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*&logo=git&logoColor=white&labelColor=585858&label=%20)](https://github.com/cssnr/stack-deploy-action/tags)
6580
[![GitHub Tag Minor](https://img.shields.io/github/v/tag/cssnr/stack-deploy-action?sort=semver&filter=!v*.*.*&logo=git&logoColor=white&labelColor=585858&label=%20)](https://github.com/cssnr/stack-deploy-action/releases)
6681
[![GitHub Release Version](https://img.shields.io/github/v/release/cssnr/stack-deploy-action?logo=git&logoColor=white&labelColor=585858&label=%20)](https://github.com/cssnr/stack-deploy-action/releases/latest)
@@ -81,3 +96,7 @@ features:
8196
[![Ko-fi](https://img.shields.io/badge/Ko--fi-72a5f2?logo=kofi&label=support)](https://ko-fi.com/cssnr)
8297

8398
</div>
99+
100+
<div class="contributors-heading">Contributors</div>
101+
102+
<Contributors />

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"dev": "vitepress dev .",
44
"build": "vitepress build .",
55
"preview": "vitepress preview .",
6-
"prettier": "npx prettier --check ."
6+
"prettier": "npx prettier --check .",
7+
"get-contributors": "node .vitepress/get-contributors.js cssnr/stack-deploy-action",
8+
"postinstall": "npm run get-contributors"
79
},
810
"dependencies": {
911
"vitepress": "^1.6.4",

0 commit comments

Comments
 (0)