--- // fetch all commits for just this page's path const path = "docs/" + Astro.props.path; const url = `https://api.github.com/repos/snowpackjs/astro/commits?path=${path}`; const commitsURL = `https://github.com/snowpackjs/astro/commits/main/${path}`; async function getCommits(url) { try { const token = import.meta.env.SNOWPACK_PUBLIC_GITHUB_TOKEN; if (!token) { throw new Error( 'Cannot find "SNOWPACK_PUBLIC_GITHUB_TOKEN" used for escaping rate-limiting.' ); } const auth = `Basic ${Buffer.from(token, "binary").toString("base64")}`; const res = await fetch(url, { method: "GET", headers: { Authorization: auth, "User-Agent": "astro-docs/1.0", }, }); const data = await res.json(); if (!res.ok) { throw new Error( `Request to fetch commits failed. Reason: ${res.statusText} Message: ${data.message}` ); } return data; } catch (e) { console.warn(`[error] /src/components/AvatarList.astro ${e?.message ?? e}`); return new Array(); } } function removeDups(arr) { if (!arr) { return new Array(); } let map = new Map(); for (let item of arr) { let author = item.author; // Deduplicate based on author.id map.set(author.id, { login: author.login, id: author.id }); } return Array.from(map.values()); } const data = await getCommits(url); const unique = removeDups(data); const recentContributors = unique.slice(0, 3); // only show avatars for the 3 most recent contributors const additionalContributors = unique.length - recentContributors.length; // list the rest of them as # of extra contributors ---
{additionalContributors > 0 && {`and ${additionalContributors} additional contributor${additionalContributors > 1 ? 's' : ''}.`}} {unique.length === 0 && Contributors}