Skip to content

Commit

Permalink
PKief#448 Update readme with contributor images
Browse files Browse the repository at this point in the history
  • Loading branch information
PKief committed Jun 11, 2019
1 parent bc9a97b commit 02f8712
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 53 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -139,7 +139,10 @@ Press `Ctrl-Shift-P` to open the command palette and type `Material Icons`.

## Contributors

<img src="https://raw.githubusercontent.com/PKief/vscode-material-icon-theme/master/images/contributors.png" alt="contributors" width="100%">
[//]: #contributors (start)
<a href="https://github.com/PKief" title="PKief"> <img src="https://avatars2.githubusercontent.com/u/12248527?v=4" width="40px" height="40px" alt="PKief"/> </a><a href="https://github.com/AdrieanKhisbe" title="AdrieanKhisbe"> <img src="https://avatars1.githubusercontent.com/u/2601132?v=4" width="40px" height="40px" alt="AdrieanKhisbe"/> </a><a href="https://github.com/dudeofawesome" title="dudeofawesome"> <img src="https://avatars0.githubusercontent.com/u/1683595?v=4" width="40px" height="40px" alt="dudeofawesome"/> </a><a href="https://github.com/wopian" title="wopian"> <img src="https://avatars0.githubusercontent.com/u/3440094?v=4" width="40px" height="40px" alt="wopian"/> </a><a href="https://github.com/Bakosa666" title="Bakosa666"> <img src="https://avatars3.githubusercontent.com/u/38684615?v=4" width="40px" height="40px" alt="Bakosa666"/> </a><a href="https://github.com/diego3g" title="diego3g"> <img src="https://avatars2.githubusercontent.com/u/2254731?v=4" width="40px" height="40px" alt="diego3g"/> </a><a href="https://github.com/felipe-fg" title="felipe-fg"> <img src="https://avatars2.githubusercontent.com/u/32036831?v=4" width="40px" height="40px" alt="felipe-fg"/> </a><a href="https://github.com/jBugman" title="jBugman"> <img src="https://avatars1.githubusercontent.com/u/891785?v=4" width="40px" height="40px" alt="jBugman"/> </a><a href="https://github.com/iFaxity" title="iFaxity"> <img src="https://avatars3.githubusercontent.com/u/9090703?v=4" width="40px" height="40px" alt="iFaxity"/> </a><a href="https://github.com/melMass" title="melMass"> <img src="https://avatars3.githubusercontent.com/u/7041726?v=4" width="40px" height="40px" alt="melMass"/> </a><a href="https://github.com/Mrgove10" title="Mrgove10"> <img src="https://avatars0.githubusercontent.com/u/25491408?v=4" width="40px" height="40px" alt="Mrgove10"/> </a><a href="https://github.com/cezarsa" title="cezarsa"> <img src="https://avatars1.githubusercontent.com/u/11041?v=4" width="40px" height="40px" alt="cezarsa"/> </a><a href="https://github.com/KristophUK" title="KristophUK"> <img src="https://avatars2.githubusercontent.com/u/6653181?v=4" width="40px" height="40px" alt="KristophUK"/> </a><a href="https://github.com/jediyozh" title="jediyozh"> <img src="https://avatars2.githubusercontent.com/u/31045769?v=4" width="40px" height="40px" alt="jediyozh"/> </a><a href="https://github.com/fahmiirsyadk" title="fahmiirsyadk"> <img src="https://avatars0.githubusercontent.com/u/17546686?v=4" width="40px" height="40px" alt="fahmiirsyadk"/> </a><a href="https://github.com/iDaN5x" title="iDaN5x"> <img src="https://avatars3.githubusercontent.com/u/3427523?v=4" width="40px" height="40px" alt="iDaN5x"/> </a><a href="https://github.com/jtiala" title="jtiala"> <img src="https://avatars2.githubusercontent.com/u/1576782?v=4" width="40px" height="40px" alt="jtiala"/> </a><a href="https://github.com/mvochoa" title="mvochoa"> <img src="https://avatars2.githubusercontent.com/u/7919838?v=4" width="40px" height="40px" alt="mvochoa"/> </a><a href="https://github.com/martin-sweeny" title="martin-sweeny"> <img src="https://avatars1.githubusercontent.com/u/3329959?v=4" width="40px" height="40px" alt="martin-sweeny"/> </a><a href="https://github.com/teototaro" title="teototaro"> <img src="https://avatars3.githubusercontent.com/u/6552833?v=4" width="40px" height="40px" alt="teototaro"/> </a><a href="https://github.com/niksudan" title="niksudan"> <img src="https://avatars1.githubusercontent.com/u/6004491?v=4" width="40px" height="40px" alt="niksudan"/> </a><a href="https://github.com/yuric18" title="yuric18"> <img src="https://avatars3.githubusercontent.com/u/18277197?v=4" width="40px" height="40px" alt="yuric18"/> </a><a href="https://github.com/denisbalyko" title="denisbalyko"> <img src="https://avatars0.githubusercontent.com/u/638190?v=4" width="40px" height="40px" alt="denisbalyko"/> </a><a href="https://github.com/dotiful" title="dotiful"> <img src="https://avatars1.githubusercontent.com/u/25269527?v=4" width="40px" height="40px" alt="dotiful"/> </a><a href="https://github.com/ycrepeau" title="ycrepeau"> <img src="https://avatars2.githubusercontent.com/u/6821466?v=4" width="40px" height="40px" alt="ycrepeau"/> </a><a href="https://github.com/aashutoshrathi" title="aashutoshrathi"> <img src="https://avatars2.githubusercontent.com/u/21199234?v=4" width="40px" height="40px" alt="aashutoshrathi"/> </a><a href="https://github.com/dabrowski-adam" title="dabrowski-adam"> <img src="https://avatars0.githubusercontent.com/u/6993966?v=4" width="40px" height="40px" alt="dabrowski-adam"/> </a><a href="https://github.com/alefesouza" title="alefesouza"> <img src="https://avatars2.githubusercontent.com/u/1693223?v=4" width="40px" height="40px" alt="alefesouza"/> </a><a href="https://github.com/baraalex" title="baraalex"> <img src="https://avatars2.githubusercontent.com/u/6618800?v=4" width="40px" height="40px" alt="baraalex"/> </a><a href="https://github.com/tothandras" title="tothandras"> <img src="https://avatars0.githubusercontent.com/u/4157749?v=4" width="40px" height="40px" alt="tothandras"/> </a><a href="https://github.com/arpadbarta" title="arpadbarta"> <img src="https://avatars3.githubusercontent.com/u/6329203?v=4" width="40px" height="40px" alt="arpadbarta"/> </a><a href="https://github.com/frederick036" title="frederick036"> <img src="https://avatars2.githubusercontent.com/u/1129770?v=4" width="40px" height="40px" alt="frederick036"/> </a><a href="https://github.com/bernardop" title="bernardop"> <img src="https://avatars1.githubusercontent.com/u/28455?v=4" width="40px" height="40px" alt="bernardop"/> </a><a href="https://github.com/bcanseco" title="bcanseco"> <img src="https://avatars3.githubusercontent.com/u/18430599?v=4" width="40px" height="40px" alt="bcanseco"/> </a><a href="https://github.com/bradlc" title="bradlc"> <img src="https://avatars0.githubusercontent.com/u/2615508?v=4" width="40px" height="40px" alt="bradlc"/> </a><a href="https://github.com/brennongs" title="brennongs"> <img src="https://avatars3.githubusercontent.com/u/24623425?v=4" width="40px" height="40px" alt="brennongs"/> </a><a href="https://github.com/chrsmutti" title="chrsmutti"> <img src="https://avatars1.githubusercontent.com/u/34144667?v=4" width="40px" height="40px" alt="chrsmutti"/> </a><a href="https://github.com/TheCloudSaver" title="TheCloudSaver"> <img src="https://avatars3.githubusercontent.com/u/39653530?v=4" width="40px" height="40px" alt="TheCloudSaver"/> </a><a href="https://github.com/danielbankhead" title="danielbankhead"> <img src="https://avatars3.githubusercontent.com/u/10792787?v=4" width="40px" height="40px" alt="danielbankhead"/> </a><a href="https://github.com/oodavid" title="oodavid"> <img src="https://avatars3.githubusercontent.com/u/46879?v=4" width="40px" height="40px" alt="oodavid"/> </a><a href="https://github.com/erikphansen" title="erikphansen"> <img src="https://avatars1.githubusercontent.com/u/20728956?v=4" width="40px" height="40px" alt="erikphansen"/> </a><a href="https://github.com/etiennetalbot" title="etiennetalbot"> <img src="https://avatars3.githubusercontent.com/u/2954511?v=4" width="40px" height="40px" alt="etiennetalbot"/> </a><a href="https://github.com/ExE-Boss" title="ExE-Boss"> <img src="https://avatars0.githubusercontent.com/u/3889017?v=4" width="40px" height="40px" alt="ExE-Boss"/> </a><a href="https://github.com/justalemon" title="justalemon"> <img src="https://avatars1.githubusercontent.com/u/11861253?v=4" width="40px" height="40px" alt="justalemon"/> </a><a href="https://github.com/JakubKoralewski" title="JakubKoralewski"> <img src="https://avatars0.githubusercontent.com/u/43069023?v=4" width="40px" height="40px" alt="JakubKoralewski"/> </a><a href="https://github.com/wersimmon" title="wersimmon"> <img src="https://avatars1.githubusercontent.com/u/185822?v=4" width="40px" height="40px" alt="wersimmon"/> </a><a href="https://github.com/JotaroS" title="JotaroS"> <img src="https://avatars2.githubusercontent.com/u/9479730?v=4" width="40px" height="40px" alt="JotaroS"/> </a><a href="https://github.com/RunningCoderLee" title="RunningCoderLee"> <img src="https://avatars3.githubusercontent.com/u/13218863?v=4" width="40px" height="40px" alt="RunningCoderLee"/> </a><a href="https://github.com/Krzysztof-Cieslak" title="Krzysztof-Cieslak"> <img src="https://avatars1.githubusercontent.com/u/5427083?v=4" width="40px" height="40px" alt="Krzysztof-Cieslak"/> </a><a href="https://github.com/kkemple" title="kkemple"> <img src="https://avatars3.githubusercontent.com/u/3629876?v=4" width="40px" height="40px" alt="kkemple"/> </a><a href="https://github.com/leohxj" title="leohxj"> <img src="https://avatars3.githubusercontent.com/u/1506900?v=4" width="40px" height="40px" alt="leohxj"/> </a><a href="https://github.com/LukasPolak" title="LukasPolak"> <img src="https://avatars3.githubusercontent.com/u/17145302?v=4" width="40px" height="40px" alt="LukasPolak"/> </a><a href="https://github.com/mjbvz" title="mjbvz"> <img src="https://avatars2.githubusercontent.com/u/12821956?v=4" width="40px" height="40px" alt="mjbvz"/> </a><a href="https://github.com/MeirionHughes" title="MeirionHughes"> <img src="https://avatars2.githubusercontent.com/u/3584509?v=4" width="40px" height="40px" alt="MeirionHughes"/> </a><a href="https://github.com/melkarm" title="melkarm"> <img src="https://avatars2.githubusercontent.com/u/32730892?v=4" width="40px" height="40px" alt="melkarm"/> </a><a href="https://github.com/epitaphmike" title="epitaphmike"> <img src="https://avatars1.githubusercontent.com/u/677832?v=4" width="40px" height="40px" alt="epitaphmike"/> </a><a href="https://github.com/olehreznichenko" title="olehreznichenko"> <img src="https://avatars0.githubusercontent.com/u/11960153?v=4" width="40px" height="40px" alt="olehreznichenko"/> </a><a href="https://github.com/TheDutchCoder" title="TheDutchCoder"> <img src="https://avatars2.githubusercontent.com/u/1668207?v=4" width="40px" height="40px" alt="TheDutchCoder"/> </a><a href="https://github.com/rhysforyou" title="rhysforyou"> <img src="https://avatars0.githubusercontent.com/u/320910?v=4" width="40px" height="40px" alt="rhysforyou"/> </a><a href="https://github.com/rfgamaral" title="rfgamaral"> <img src="https://avatars1.githubusercontent.com/u/96476?v=4" width="40px" height="40px" alt="rfgamaral"/> </a><a href="https://github.com/kukiric" title="kukiric"> <img src="https://avatars2.githubusercontent.com/u/6194377?v=4" width="40px" height="40px" alt="kukiric"/> </a><a href="https://github.com/richardmillen94" title="richardmillen94"> <img src="https://avatars2.githubusercontent.com/u/22445885?v=4" width="40px" height="40px" alt="richardmillen94"/> </a><a href="https://github.com/richiksc" title="richiksc"> <img src="https://avatars1.githubusercontent.com/u/8939680?v=4" width="40px" height="40px" alt="richiksc"/> </a><a href="https://github.com/Faultless" title="Faultless"> <img src="https://avatars1.githubusercontent.com/u/7265811?v=4" width="40px" height="40px" alt="Faultless"/> </a><a href="https://github.com/sbekrin" title="sbekrin"> <img src="https://avatars0.githubusercontent.com/u/9248479?v=4" width="40px" height="40px" alt="sbekrin"/> </a><a href="https://github.com/leggsimon" title="leggsimon"> <img src="https://avatars2.githubusercontent.com/u/11544418?v=4" width="40px" height="40px" alt="leggsimon"/> </a><a href="https://github.com/ffrinds" title="ffrinds"> <img src="https://avatars3.githubusercontent.com/u/26288489?v=4" width="40px" height="40px" alt="ffrinds"/> </a><a href="https://github.com/ThomasGeek" title="ThomasGeek"> <img src="https://avatars1.githubusercontent.com/u/10091122?v=4" width="40px" height="40px" alt="ThomasGeek"/> </a><a href="https://github.com/timsneath" title="timsneath"> <img src="https://avatars3.githubusercontent.com/u/2319867?v=4" width="40px" height="40px" alt="timsneath"/> </a><a href="https://github.com/titouancreach" title="titouancreach"> <img src="https://avatars1.githubusercontent.com/u/3995719?v=4" width="40px" height="40px" alt="titouancreach"/> </a><a href="https://github.com/Happycoil" title="Happycoil"> <img src="https://avatars2.githubusercontent.com/u/12999248?v=4" width="40px" height="40px" alt="Happycoil"/> </a><a href="https://github.com/william-lohan" title="william-lohan"> <img src="https://avatars3.githubusercontent.com/u/8146733?v=4" width="40px" height="40px" alt="william-lohan"/> </a><a href="https://github.com/dmay" title="dmay"> <img src="https://avatars0.githubusercontent.com/u/1068398?v=4" width="40px" height="40px" alt="dmay"/> </a><a href="https://github.com/eyal0803" title="eyal0803"> <img src="https://avatars1.githubusercontent.com/u/5116133?v=4" width="40px" height="40px" alt="eyal0803"/> </a><a href="https://github.com/mintapp" title="mintapp"> <img src="https://avatars0.githubusercontent.com/u/37894041?v=4" width="40px" height="40px" alt="mintapp"/> </a><a href="https://github.com/natemoo-re" title="natemoo-re"> <img src="https://avatars0.githubusercontent.com/u/7118177?v=4" width="40px" height="40px" alt="natemoo-re"/> </a><a href="https://github.com/suazithustra" title="suazithustra"> <img src="https://avatars3.githubusercontent.com/u/33040041?v=4" width="40px" height="40px" alt="suazithustra"/> </a><a href="https://github.com/khrystuk" title="khrystuk"> <img src="https://avatars2.githubusercontent.com/u/22624868?v=4" width="40px" height="40px" alt="khrystuk"/> </a>

[//]: #contributors (end)

**You also want to contribute?**

Expand Down
Binary file removed images/contributors.png
Binary file not shown.
5 changes: 5 additions & 0 deletions src/models/scripts/contributors/contributorOptions.ts
@@ -0,0 +1,5 @@
export interface ContributorOptions {
username: string;
repo: string;
imageSize: number;
}
22 changes: 0 additions & 22 deletions src/scripts/contributors/contributors.css

This file was deleted.

68 changes: 38 additions & 30 deletions src/scripts/contributors/index.ts
Expand Up @@ -2,8 +2,8 @@ import * as fs from 'fs';
import * as https from 'https';
import * as path from 'path';
import { Contributor } from '../../models/scripts/contributors/contributor';
import { ContributorOptions } from '../../models/scripts/contributors/contributorOptions';
import * as painter from '../helpers/painter';
import { createScreenshot } from '../helpers/screenshots';

/**
* Parse link header
Expand All @@ -25,12 +25,13 @@ const parseLinkHeader = (linkHeader: string) => {
/**
* Get all contributors from GitHub API.
*/
const fetchContributors = (page: string): Promise<{ contributorsOfPage: Contributor[], nextPage: string }> => {
const fetchContributors = (page: string, username: string, repo: string):
Promise<{ contributorsOfPage: Contributor[], nextPage: string }> => {
return new Promise((resolve, reject) => {
const requestOptions: https.RequestOptions = {
method: 'GET',
hostname: 'api.github.com',
path: `/repos/pkief/vscode-material-icon-theme/contributors?page=${page}`,
path: `/repos/${username}/${repo}/contributors?page=${page}`,
port: 443,
headers: {
'link': 'next',
Expand All @@ -40,7 +41,9 @@ const fetchContributors = (page: string): Promise<{ contributorsOfPage: Contribu
};

const req = https.request(requestOptions, (res) => {
const { nextPage, lastPage, prevPage } = parseLinkHeader(res.headers.link.toString());
const { nextPage, lastPage, prevPage } = res.headers.link ? parseLinkHeader(res.headers.link.toString()) : {
nextPage: undefined, lastPage: [undefined, 1], prevPage: undefined,
};
console.log('> Material Icon Theme:', painter.yellow(`[${page}/${lastPage ? lastPage[1] : +prevPage[1] + 1}] Loading contributors from GitHub...`));
const result = [];
res.on('data', (data: Buffer) => {
Expand Down Expand Up @@ -68,47 +71,52 @@ const fetchContributors = (page: string): Promise<{ contributorsOfPage: Contribu
});
};

const createContributorsList = (contributors: Contributor[]) => {
const list = contributors.map(c => {
return `<li title="${c.login}"><img src="${c.avatar_url}" alt="${c.login}"/></li>`;
}).join('\n');

const htmlDoctype = `<!DOCTYPE html>`;
const styling = `<link rel="stylesheet" href="contributors.css">`;
const generatedHtml = `${htmlDoctype}${styling}<ul>${list}</ul>`;

const outputPath = path.join(__dirname, 'contributors.html');
fs.writeFileSync(outputPath, generatedHtml);
return outputPath;
/**
* Generates a list of linked images
* @param contributors List of contributors
* @param imageSize Size of the images in pixels
*/
const createLinkedImages = (contributors: Contributor[], imageSize: number = 40) => {
const linkList = contributors.map(c => {
return `<a href="${c.html_url}" title="${c.login}">
<img src="${c.avatar_url}" width="${imageSize}px" height="${imageSize}px" alt="${c.login}"/>
</a>`;
}).join('').replace(/\s{2,}/g, ' '); // remove whitespace

return linkList;
};

const init = async () => {
const contributorsList: Contributor[] = [];
const updateContributors = async ({ username, repo, imageSize }: ContributorOptions) => {
const contributors: Contributor[] = [];
let page = '1';

// iterate over the pages of GitHub API
while (page !== undefined) {
const result = await fetchContributors(page);
contributorsList.push(...result.contributorsOfPage);
const result = await fetchContributors(page, username, repo);
contributors.push(...result.contributorsOfPage);
page = result.nextPage;
}

if (contributorsList.length > 0) {
if (contributors.length > 0) {
console.log('> Material Icon Theme:', painter.green(`Successfully fetched all contributors from GitHub!`));
} else {
console.log('> Material Icon Theme:', painter.red(`Error: Could not fetch contributors from GitHub!`));
throw Error();
}
const outputPath = createContributorsList(contributorsList);
const images = createLinkedImages(contributors, imageSize);

// create the image
console.log('> Material Icon Theme:', painter.yellow(`Creating image...`));
const fileName = 'contributors';
createScreenshot(outputPath, fileName).then(() => {
console.log('> Material Icon Theme:', painter.green(`Successfully created ${fileName} image!`));
}).catch(() => {
throw Error(painter.red(`Error while creating ${fileName} image`));
});
console.log('> Material Icon Theme:', painter.yellow(`Updating README.md ...`));
const readmePath = path.join(process.cwd(), 'README.md');

const readmeContent = fs.readFileSync(readmePath, 'utf8');
const getContributorsSectionPattern = new RegExp(/(\[\/\/\]:\s#contributors\s\(start\))([\s\S]*)(\[\/\/\]:\s#contributors\s\(end\))/);
const updatedContent = readmeContent.replace(getContributorsSectionPattern, `$1\n${images}\n\n$3`);
fs.writeFileSync(readmePath, updatedContent);
};

init();
updateContributors({
username: 'pkief',
repo: 'vscode-material-icon-theme',
imageSize: 40,
});

0 comments on commit 02f8712

Please sign in to comment.