From c892408cd7e4510f0dc03bac3f54d6cd09633c44 Mon Sep 17 00:00:00 2001 From: Aron Buzinkay Date: Fri, 21 May 2021 18:14:57 +0200 Subject: [PATCH 1/3] Removed GitHub API keys --- site/scripts/get-contributors.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/site/scripts/get-contributors.js b/site/scripts/get-contributors.js index cb1facb874b7..4b8b19a4b796 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; From eb46ca906613aef633d69cb3fef1f074afec2e16 Mon Sep 17 00:00:00 2001 From: Aron Buzinkay Date: Fri, 21 May 2021 18:24:27 +0200 Subject: [PATCH 2/3] Added automatic image optimization for contributors.jpg --- site/scripts/get-contributors.js | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/site/scripts/get-contributors.js b/site/scripts/get-contributors.js index 4b8b19a4b796..2b2760c3a507 100644 --- a/site/scripts/get-contributors.js +++ b/site/scripts/get-contributors.js @@ -39,9 +39,29 @@ 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, (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)]); + + fetch('https://api.resmush.it/ws.php', { + method: 'POST', + headers: { + "Content-type": 'multipart/form-data; boundary=xxxxxxxxxx', + }, + body: body + }).then(async (res) => { + let response = await res.json() + console.log(`Reduced file size by ${response.percent}%`) + + fetch(response.dest).then(async image => { + fs.writeFileSync('../static/contributors.jpg', await image.buffer()); + }); + }); + }); const str = `[\n\t${authors.map(a => `'${a.login}'`).join(',\n\t')}\n]`; From a70e3d164832aa94f574871363a2325d69e78edd Mon Sep 17 00:00:00 2001 From: Aron Buzinkay Date: Mon, 28 Jun 2021 03:58:14 +0200 Subject: [PATCH 3/3] Switched to await instead of then --- site/scripts/get-contributors.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/site/scripts/get-contributors.js b/site/scripts/get-contributors.js index 2b2760c3a507..e58cd062849d 100644 --- a/site/scripts/get-contributors.js +++ b/site/scripts/get-contributors.js @@ -39,7 +39,7 @@ async function main() { sprite.composite(image, i * SIZE, 0); } - await sprite.quality(80).getBuffer(Jimp.MIME_JPEG, (err, buffer) => { + 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`; @@ -47,20 +47,19 @@ async function main() { let body = Buffer.concat([Buffer.from(content, "utf8"), new Buffer(buffer, "binary"), Buffer.from(end)]); - fetch('https://api.resmush.it/ws.php', { + let response = await fetch('https://api.resmush.it/ws.php', { method: 'POST', headers: { "Content-type": 'multipart/form-data; boundary=xxxxxxxxxx', }, body: body - }).then(async (res) => { - let response = await res.json() - console.log(`Reduced file size by ${response.percent}%`) - - fetch(response.dest).then(async image => { - fs.writeFileSync('../static/contributors.jpg', await image.buffer()); - }); - }); + }) + + 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]`;