From 495157cc6a94548bd5c3cae3c79b6cb5eb9112e2 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Thu, 5 May 2016 17:30:15 +0200 Subject: [PATCH] Handle image resizing for users without an avatar. Fixes #14 --- lib/generate/format-contributor.js | 15 +++-------- lib/generate/format-contributor.test.js | 33 +++++-------------------- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/lib/generate/format-contributor.js b/lib/generate/format-contributor.js index d71b6d9..60479fe 100644 --- a/lib/generate/format-contributor.js +++ b/lib/generate/format-contributor.js @@ -3,7 +3,7 @@ var _ = require('lodash/fp'); var formatContributionType = require('./format-contribution-type'); -var avatarTemplate = _.template('![<%= contributor.name %>](<%= contributor.avatar_url %>)'); +var avatarTemplate = _.template(''); var avatarBlockTemplate = _.template('[<%= avatar %>
<%= contributor.name %>](<%= contributor.profile %>)'); var contributorTemplate = _.template('<%= avatarBlock %>
<%= contributions %>'); @@ -15,15 +15,6 @@ function defaultTemplate(templateData) { return contributorTemplate(_.assign({avatarBlock: avatarBlock}, templateData)); } -function updateAvatarUrl(options, contributor) { - var avatarUrl = contributor.avatar_url; - var paramJoiner = _.includes('?', avatarUrl) ? '&' : '?'; - var imageSize = options.imageSize || defaultImageSize; - return _.assign(contributor, { - avatar_url: avatarUrl + paramJoiner + 's=' + imageSize - }); -} - module.exports = function formatContributor(options, contributor) { var formatter = _.partial(formatContributionType, [options, contributor]); var contributions = contributor.contributions @@ -31,8 +22,8 @@ module.exports = function formatContributor(options, contributor) { .join(' '); var templateData = { contributions: contributions, - contributor: updateAvatarUrl(options, contributor), - options: options + contributor: contributor, + options: _.assign({imageSize: defaultImageSize}, options) }; var customTemplate = options.contributorTemplate && _.template(options.contributorTemplate); return (customTemplate || defaultTemplate)(templateData); diff --git a/lib/generate/format-contributor.test.js b/lib/generate/format-contributor.test.js index f152cd0..7c10785 100644 --- a/lib/generate/format-contributor.test.js +++ b/lib/generate/format-contributor.test.js @@ -16,7 +16,7 @@ test('should format a simple contributor', t => { const contributor = _.assign(contributors.kentcdodds, {contributions: ['review']}); const {options} = fixtures(); - const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)
Kent C. Dodds](http://kentcdodds.com)
👀'; + const expected = '[
Kent C. Dodds](http://kentcdodds.com)
👀'; t.is(formatContributor(options, contributor), expected); }); @@ -25,7 +25,7 @@ test('should format contributor with complex contribution types', t => { const contributor = contributors.kentcdodds; const {options} = fixtures(); - const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)
Kent C. Dodds](http://kentcdodds.com)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) 👀 💁'; + const expected = '[
Kent C. Dodds](http://kentcdodds.com)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) 👀 💁'; t.is(formatContributor(options, contributor), expected); }); @@ -40,33 +40,12 @@ test('should format contributor using custom template', t => { t.is(formatContributor(options, contributor), expected); }); -test('should add image size to url', t => { - const {options} = fixtures(); - const contributor = contributors.kentcdodds; - options.contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>'; - - var contributionWithoutQuestionMarkUrl = _.assign(contributor, { - avatar_url: 'www.some-url-without-question-mark.com' - }); - var contributionWithQuestionMarkUrl = _.assign(contributor, { - avatar_url: 'www.some-url-with-question-mark.com?v=3' - }); - - t.is(formatContributor(options, contributionWithoutQuestionMarkUrl), - 'Kent C. Dodds at www.some-url-without-question-mark.com?s=150' - ); - t.is(formatContributor(options, contributionWithQuestionMarkUrl), - 'Kent C. Dodds at www.some-url-with-question-mark.com?v=3&s=150' - ); -}); - test('should default image size to 100', t => { + const contributor = _.assign(contributors.kentcdodds, {contributions: ['review']}); const {options} = fixtures(); - const contributor = contributors.kentcdodds; - options.contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>'; delete options.imageSize; - t.is(formatContributor(options, contributor), - 'Kent C. Dodds at https://avatars1.githubusercontent.com/u/1500684?s=100' - ); + const expected = '[
Kent C. Dodds](http://kentcdodds.com)
👀'; + + t.is(formatContributor(options, contributor), expected); });