bmen-jekyll/assets/js/remote-projects.js

25 lines
715 B
JavaScript
Raw Normal View History

2020-10-10 08:35:47 +00:00
function get_tools(repo) {
fetch(`https://api.github.com/repos/${repo}/topics`, {
headers: {
Accept: "application/vnd.github.mercy-preview+json"
}
})
.then(response => response.json())
.then(data => {
var name = repo.split("/")[1];
var parent = document.getElementById(`${name}-tools`);
parse_tools(data.names).forEach(t => parent.appendChild(t));
});
}
function parse_tools(tools) {
var classes = "badge badge-pill text-primary border border-primary ml-1";
var classesArr = classes.split(" ");
return tools.map(tool => {
var span = document.createElement("span");
span.classList.add(...classesArr);
span.innerHTML = tool;
return span;
});
}