import fetch from "node-fetch"; // don't continue if there isn't a span#meta-hits element on this page const wrapper = document.getElementById("github-cards"); if (wrapper) { fetch("/api/projects/?top") .then((response) => response.json()) .then((data) => { type Repository = { name: string; url: string; description: string; primaryLanguage?: { color: string; name: string; }; stargazerCount: number; stargazerCount_pretty?: string; forkCount: number; forkCount_pretty?: string; pushedAt: string; pushedAt_relative?: string; }; data.forEach((repo: Repository) => { let html = ` ${repo.name}
${repo.description}
`; if (repo.primaryLanguage) { html += ` `; } if (repo.stargazerCount > 0) { html += ` `; } if (repo.forkCount > 0) { html += ` `; } html += ` `; const div = document.createElement("div"); div.classList.add("github-card"); div.innerHTML = html; wrapper.appendChild(div); }); }) .catch(() => { // something went horribly wrong, initiate coverup wrapper.style.display = "none"; }); }