forked from mne-tools/mne-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Show contributor image on homepage (mne-tools#11819)
Co-authored-by: Daniel McCloy <dan@mccloy.info>
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
async function getContribs(url) { | ||
result = await fetch(url); | ||
data = await result.json(); | ||
return data; | ||
} | ||
|
||
function addCards(data, container) { | ||
data.forEach((entry) => { | ||
let card = document.createElement("div"); | ||
let anchor = document.createElement("a"); | ||
let image = document.createElement("img"); | ||
card.setAttribute("class", "card my-1 mx-2"); | ||
anchor.setAttribute("href", entry.html_url); | ||
image.setAttribute("class", "card-img contributor-avatar"); | ||
image.setAttribute("src", entry.avatar_url); | ||
image.setAttribute("title", entry.login); | ||
image.setAttribute("alt", `Contributor avatar for ${entry.login}`); | ||
anchor.append(image); | ||
card.append(anchor); | ||
container.append(card); | ||
}); | ||
} | ||
|
||
async function putAvatarsInPage() { | ||
// container | ||
const outer = document.createElement("div"); | ||
const title = document.createElement("p"); | ||
const inner = document.createElement("div"); | ||
outer.setAttribute("id", "contributor-avatars"); | ||
outer.setAttribute("class", "container my-4"); | ||
title.setAttribute("class", "h4 text-center font-weight-light"); | ||
title.innerText = "Contributors"; | ||
inner.setAttribute("class", "d-flex flex-wrap flex-row justify-content-center align-items-center"); | ||
// GitHub API returns batches of 100 so we have to loop | ||
var page = 1; | ||
while (true) { | ||
data = await getContribs( | ||
`https://api.github.com/repos/mne-tools/mne-python/contributors?per_page=100&page=${page}` | ||
); | ||
if (!data.length) { | ||
break; | ||
} | ||
addCards(data, container=inner); | ||
page++; | ||
} | ||
// finish | ||
outer.append(title, inner); | ||
document.getElementById("institution-logos").after(outer); | ||
} | ||
|
||
putAvatarsInPage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters