From 347fa403c4c035b7abc5bfdd334ca6d98c72c77e Mon Sep 17 00:00:00 2001 From: Caleb Date: Sat, 27 Jan 2018 11:42:13 -0700 Subject: [PATCH] Use scaled avatars for website contributors. Right now we are using full size contributor avatars on the website, which really slows down the loading. This PR allows us to use avatars scaled down to the size that we are actually using. --- website/gulpfile.babel.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/website/gulpfile.babel.js b/website/gulpfile.babel.js index ab8b757c..dcc84a85 100755 --- a/website/gulpfile.babel.js +++ b/website/gulpfile.babel.js @@ -17,6 +17,7 @@ import styleVariables from "./config/variables"; import BrowserSync from "browser-sync"; import webpack from "webpack"; import webpackConfig from "./webpack.conf"; +import url from "url"; const browserSync = BrowserSync.create(); const defaultArgs = ["-d", "../dist", "-s", "site", "-v"]; @@ -99,8 +100,17 @@ gulp.task("copy", () => "utf8", content => new Promise((resolve, reject) => { - const contributors = JSON.parse(content); - resolve(yaml.dump({ contributors: contributors.contributors })); + const contributors = JSON.parse(content).contributors.map(c => { + const avatar = url.parse(c['avatar_url'], true); + avatar.search = undefined; // Override so that we can use `avatar.query`. + if (avatar.hostname.endsWith('githubusercontent.com')) { + // Use 32px avatars, instead of full-size. + avatar.query['s'] = '32'; + } + const avatar_url = url.format(avatar); + return Object.assign({}, c, { avatar_url }); + }); + resolve(yaml.dump({ contributors })); }) ) )