1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-15 05:19:58 +00:00
elk/scripts/avatars.ts
renovate[bot] dd6fab86ee
chore(deps): update dependency nuxt to ^3.13.1 (#2946)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Daniel Roe <daniel@roe.dev>
2024-09-11 14:37:59 +00:00

32 lines
872 B
TypeScript

import { writeFile } from 'node:fs/promises'
import { join, resolve } from 'pathe'
import fs from 'fs-extra'
import { ofetch } from 'ofetch'
import { elkTeamMembers } from '../composables/about'
const avatarsDir = resolve('./public/avatars/')
const sizes = [60, 100]
async function download(url: string, fileName: string) {
console.log('downloading', fileName)
try {
const image = await ofetch(url, { responseType: 'arrayBuffer' })
await writeFile(fileName, new Uint8Array(image))
}
catch (err) {
console.error(err)
}
}
async function fetchAvatars() {
await fs.ensureDir(avatarsDir)
await Promise.all(elkTeamMembers.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()