diff --git a/site/scripts/get-contributors.js b/site/scripts/get-contributors.js index cb1facb874b7..e58cd062849d 100644 --- a/site/scripts/get-contributors.js +++ b/site/scripts/get-contributors.js @@ -1,4 +1,3 @@ -require('dotenv/config'); const fs = require('fs'); const fetch = require('node-fetch'); const Jimp = require('jimp'); @@ -6,7 +5,6 @@ const Jimp = require('jimp'); process.chdir(__dirname); const base = `https://api.github.com/repos/sveltejs/svelte/contributors`; -const { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET } = process.env; const SIZE = 64; @@ -15,7 +13,7 @@ async function main() { let page = 1; while (true) { - const res = await fetch(`${base}?client_id=${GITHUB_CLIENT_ID}&client_secret=${GITHUB_CLIENT_SECRET}&per_page=100&page=${page++}`); + const res = await fetch(`${base}?per_page=100&page=${page++}`); const list = await res.json(); if (list.length === 0) break; @@ -41,9 +39,28 @@ async function main() { sprite.composite(image, i * SIZE, 0); } - await sprite.quality(80).write(`../static/contributors.jpg`); - // TODO: Optimizing the static/contributors.jpg image should probably get automated as well - console.log('remember to additionally optimize the resulting /static/contributors.jpg image file via e.g. https://squoosh.app '); + await sprite.quality(80).getBuffer(Jimp.MIME_JPEG, async (err, buffer) => { + let quality = 75; + + let content = `--xxxxxxxxxx\r\nContent-Disposition: form-data; name="qlty"; \r\n\r\n${quality}\r\n--xxxxxxxxxx\r\nContent-Disposition: form-data; name="files"; filename="contributors.jpg"\r\nContent-Type:application/octet-stream\r\n\r\n`; + let end = `\r\n--xxxxxxxxxx--\r\n`; + + let body = Buffer.concat([Buffer.from(content, "utf8"), new Buffer(buffer, "binary"), Buffer.from(end)]); + + let response = await fetch('https://api.resmush.it/ws.php', { + method: 'POST', + headers: { + "Content-type": 'multipart/form-data; boundary=xxxxxxxxxx', + }, + body: body + }) + + let responseBody = await response.json(); + console.log(`Reduced file size by ${responseBody.percent}%`); + + let image = await fetch(responseBody.dest); + fs.writeFileSync('../static/contributors.jpg', await image.buffer()); + }); const str = `[\n\t${authors.map(a => `'${a.login}'`).join(',\n\t')}\n]`;