perf: use team avatars from local (#793)
This commit is contained in:
parent
d279d618a5
commit
95c825522e
12 changed files with 34 additions and 2 deletions
31
scripts/avatars.ts
Normal file
31
scripts/avatars.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { join, resolve } from 'pathe'
|
||||
import fs from 'fs-extra'
|
||||
import { $fetch } from 'ohmyfetch'
|
||||
import { teams } from '../composables/about'
|
||||
|
||||
const avatarsDir = resolve('./public/avatars/')
|
||||
|
||||
const sizes = [60, 100]
|
||||
|
||||
async function download(url: string, fileName: string) {
|
||||
if (fs.existsSync(fileName))
|
||||
return
|
||||
|
||||
console.log('downloading', fileName)
|
||||
try {
|
||||
const image = await $fetch(url, { responseType: 'arrayBuffer' })
|
||||
await fs.writeFile(fileName, Buffer.from(image))
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
|
||||
async function fetchAvatars() {
|
||||
await fs.ensureDir(avatarsDir)
|
||||
|
||||
await Promise.all(teams.reduce((acc, { github }) => {
|
||||
acc.push(...sizes.map(s => download(`https://github.com/${github}.png?size=${s}`, join(avatarsDir, `${github}-${s}x${s}.png`))))
|
||||
return acc
|
||||
}, [] as Promise<void>[]))
|
||||
}
|
||||
|
||||
fetchAvatars()
|
Loading…
Add table
Add a link
Reference in a new issue