Skip to content

Commit e5e968b

Browse files
committed
Add Contributors.vue
1 parent 5adc5f2 commit e5e968b

File tree

9 files changed

+157
-19
lines changed

9 files changed

+157
-19
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
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs')
3+
const path = require('path')
4+
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+
}
14+
15+
fs.mkdirSync(path.dirname(file), { recursive: true })
16+
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+
})()
26+
27+
async function githubContributors(repo) {
28+
let results = []
29+
let page = 1
30+
31+
while (true) {
32+
const url = `https://api.github.com/repos/${repo}/contributors?per_page=100&page=${page}`
33+
const data = { headers: { Accept: 'application/vnd.github+json' } }
34+
35+
const response = await fetch(url, data)
36+
// console.log('response:', response)
37+
if (!response.ok) break
38+
39+
const contributors = await response.json()
40+
// console.log('contributors:', contributors)
41+
if (!contributors.length) break
42+
43+
const filtered = contributors
44+
.filter((c) => c.type === 'User')
45+
.map((c) => ({
46+
login: c.login,
47+
avatar_url: c.avatar_url,
48+
contributions: c.contributions,
49+
}))
50+
// console.log('filtered:', filtered)
51+
52+
results.push(...filtered)
53+
page++
54+
await new Promise((resolve) => setTimeout(resolve, 250))
55+
}
56+
57+
return results
58+
}

.vitepress/theme/components/BrowserIcons.vue

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ if (props.centered) iconStyle.textAlign = 'center'
3030
if (props.margin) iconStyle.margin = props.margin
3131
</script>
3232

33+
<template>
34+
<div class="browser-icons" :style="iconStyle">
35+
<a
36+
v-for="browser in browsers"
37+
:key="browser.name"
38+
:href="browser.url"
39+
:title="browser.name"
40+
class="px-1 hvr-grow-lg"
41+
target="_blank"
42+
rel="noopener"
43+
>
44+
<img :alt="browser.name" :src="`${baseUrl}/${browser.img}`" :class="imageClass" width="48" height="48" />
45+
</a>
46+
</div>
47+
</template>
48+
3349
<style scoped>
3450
.browser-icons {
3551
min-height: 48px;
@@ -48,19 +64,3 @@ if (props.margin) iconStyle.margin = props.margin
4864
transform: scale(1.2);
4965
}
5066
</style>
51-
52-
<template>
53-
<div class="browser-icons" :style="iconStyle">
54-
<a
55-
v-for="browser in browsers"
56-
:key="browser.name"
57-
:href="browser.url"
58-
:title="browser.name"
59-
class="px-1 hvr-grow-lg"
60-
target="_blank"
61-
rel="noopener"
62-
>
63-
<img :alt="browser.name" :src="`${baseUrl}/${browser.img}`" :class="imageClass" width="48" height="48" />
64-
</a>
65-
</div>
66-
</template>
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,6 +2,7 @@ import DefaultTheme from 'vitepress/theme'
22
import './custom.css'
33

44
import BrowserIcons from './components/BrowserIcons.vue'
5+
import Contributors from './components/Contributors.vue'
56
import VPCardLink from './components/VPCardLink.vue'
67

78
import VPSwiper from '@cssnr/vitepress-swiper'
@@ -13,6 +14,7 @@ export default {
1314

1415
enhanceApp({ app }) {
1516
app.component('BrowserIcons', BrowserIcons)
17+
app.component('Contributors', Contributors)
1618
app.component('VPCardLink', VPCardLink)
1719
app.component('VPSwiper', VPSwiper)
1820
},

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![GitHub Deployments](https://img.shields.io/github/deployments/django-files/django-files.github.io/github-pages?logo=github&label=deploy)](https://github.com/django-files/django-files.github.io/deployments)
2-
[![Pages](https://img.shields.io/github/actions/workflow/status/django-files/django-files.github.io/pages.yaml?logo=cachet&label=pages)](https://github.com/django-files/django-files.github.io/actions/workflows/pages.yaml)
3-
[![Lint](https://img.shields.io/github/actions/workflow/status/django-files/django-files.github.io/lint.yaml?logo=cachet&label=lint)](https://github.com/django-files/django-files.github.io/actions/workflows/lint.yaml)
2+
[![GitHub Pages](https://img.shields.io/github/actions/workflow/status/django-files/django-files.github.io/pages.yaml?logo=cachet&label=pages)](https://github.com/django-files/django-files.github.io/actions/workflows/pages.yaml)
3+
[![GitHub Lint](https://img.shields.io/github/actions/workflow/status/django-files/django-files.github.io/lint.yaml?logo=cachet&label=lint)](https://github.com/django-files/django-files.github.io/actions/workflows/lint.yaml)
44
[![GitHub Last Commit](https://img.shields.io/github/last-commit/django-files/django-files.github.io?logo=vitepress&logoColor=white&label=updated)](https://github.com/django-files/django-files.github.io/pulse)
55
[![GitHub Contributors](https://img.shields.io/github/contributors/django-files/django-files.github.io?logo=github)](https://github.com/django-files/django-files.github.io/graphs/contributors)
66
[![GitHub Repo Size](https://img.shields.io/github/repo-size/django-files/django-files.github.io?logo=bookstack&logoColor=white&label=repo%20size)](https://github.com/django-files/django-files.github.io)

docs/index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,20 @@ features:
4343
details: Meet our Team of Bots
4444
link: /team
4545
---
46+
47+
---
48+
49+
Contributors
50+
51+
<Contributors />
52+
53+
<style>
54+
.vp-doc.container {
55+
margin-top: 96px;
56+
text-align: center;
57+
}
58+
.vp-doc p:first-of-type {
59+
text-align: center;
60+
font-size: 1.5em;
61+
}
62+
</style>

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+
"postinstall": "npm run get-contributors",
8+
"get-contributors": "node .vitepress/scripts/get-contributors.js django-files/django-files"
79
},
810
"dependencies": {
911
"@cssnr/vitepress-swiper": "^0.0.7",

0 commit comments

Comments
 (0)