9194ef5abd
Docs/Test Workflow / Test docs build (push) Failing after 0s
Check links & references / links-check (push) Failing after 1s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.10) (push) Failing after 0s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.11) (push) Failing after 0s
PR Conflict Labeler / main (push) Failing after 2s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.12) (push) Failing after 2s
Pytest/Test Workflow / Import Test and Pytest Run (ubuntu-latest, 3.13) (push) Failing after 0s
Pytest/Test Workflow / Build this Package (push) Failing after 5s
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (macos-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.10) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.11) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.12) (push) Has been cancelled
Pytest/Test Workflow / Import Test and Pytest Run (windows-latest, 3.13) (push) Has been cancelled
Pytest/Test Workflow / testing-guardian (push) Has been cancelled
144 lines
5.3 KiB
JavaScript
144 lines
5.3 KiB
JavaScript
document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
const palette = __md_get("__palette")
|
|
const useDark = palette && typeof palette.color === "object" && palette.color.scheme === "slate"
|
|
const theme = useDark ? "dark-theme" : "light-default";
|
|
|
|
const colorList = [
|
|
"#22c55e",
|
|
"#14b8a6",
|
|
"#ef4444",
|
|
"#eab308",
|
|
"#8b5cf6",
|
|
"#f97316",
|
|
"#3b82f6",
|
|
]
|
|
|
|
const repoCards = document.querySelectorAll(".repo-card");
|
|
const labelsAll = Array
|
|
.from(repoCards)
|
|
.flatMap((element) => element.getAttribute('data-labels').split(','))
|
|
.map(label => label.trim())
|
|
.filter(label => label !== '');
|
|
const uniqueLabels = [...new Set(labelsAll)];
|
|
|
|
const labelToColor = uniqueLabels.reduce((map, label, index) => {
|
|
map[label] = colorList[index % colorList.length];
|
|
return map;
|
|
}, {});
|
|
|
|
|
|
async function renderCard(element, elementIndex) {
|
|
const name = element.getAttribute('data-name');
|
|
const labels = element.getAttribute('data-labels');
|
|
const version = element.getAttribute('data-version');
|
|
const authors = element.getAttribute('data-author');
|
|
|
|
const labelHTML = labels ? labels.split(',').filter(label => label !== '').map((label, index) => {
|
|
const color = labelToColor[label.trim()];
|
|
return `
|
|
<span
|
|
class="label non-selectable-text"
|
|
style="background-color: ${color}"
|
|
>
|
|
${label.trim()}
|
|
</span>
|
|
`;
|
|
}).join(' ') : '';
|
|
|
|
const authorArray = authors.split(',');
|
|
const authorDataArray = await Promise.all(authorArray.map(async (author) => {
|
|
const response = await fetch(`https://api.github.com/users/${author.trim()}`);
|
|
return await response.json();
|
|
}));
|
|
|
|
let authorAvatarsHTML = authorDataArray.map((authorData, index) => {
|
|
const marginLeft = index === 0 ? '0' : '-10px';
|
|
const zIndex = 4 - index;
|
|
return `
|
|
<div
|
|
class="author-container"
|
|
data-login="${authorData.login}-${elementIndex}"
|
|
style="margin-left: ${marginLeft};"
|
|
>
|
|
<a
|
|
href="https://github.com/${authorData.login}"
|
|
target="_blank"
|
|
style="line-height: 0;"
|
|
>
|
|
<img
|
|
class="author-avatar"
|
|
src="${authorData.avatar_url}"
|
|
alt="${authorData.login}'s avatar"
|
|
>
|
|
</a>
|
|
</div>
|
|
`;
|
|
}).join('');
|
|
|
|
let authorNamesHTML = authorDataArray.map(
|
|
authorData => `
|
|
<span
|
|
class="author-name"
|
|
data-login="${authorData.login}-${elementIndex}"
|
|
style="color: ${theme.color}"
|
|
>
|
|
<a href="https://github.com/${authorData.login}" target="_blank">
|
|
${authorData.login}
|
|
</a>
|
|
</span>`
|
|
).join(', ');
|
|
|
|
let authorsHTML = `
|
|
<div class="authors" style="margin: 0;">
|
|
${authorAvatarsHTML}
|
|
<div class="author-names">${authorNamesHTML}</div>
|
|
</div>
|
|
`;
|
|
|
|
element.innerText = `
|
|
<div style="
|
|
display: grid !important;
|
|
grid-template-rows: auto;
|
|
height: 100%;
|
|
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji; background: ${theme.background}; font-size: 14px; line-height: 1.5; color: ${theme.color}">
|
|
<div style="display: flex; align-items: center;">
|
|
<span style="font-weight: 700; font-size: 1rem; color: ${theme.linkColor};">
|
|
${name}
|
|
</span>
|
|
</div>
|
|
${authorsHTML}
|
|
<div style="font-size: 12px; color: ${theme.color}; display: grid; grid-template-columns: auto 3fr; justify-content: space-between; gap: 1rem;">
|
|
<div style="display: flex; align-items: center;">
|
|
<img src="/assets/supervision-lenny.png" aria-label="stars" width="20" height="20" role="img" />
|
|
|
|
<span style="margin-left: 4px">${version}</span>
|
|
</div>
|
|
<div style="display: flex; align-items: center; flex-wrap: wrap; align-content: right;
|
|
gap: 0.1rem;">
|
|
${labelHTML}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
let sanitizedHTML = DOMPurify.sanitize(element.innerText);
|
|
element.innerHTML = sanitizedHTML;
|
|
|
|
document.querySelectorAll('.author-name').forEach(element => {
|
|
element.addEventListener('mouseenter', function () {
|
|
const login = this.getAttribute('data-login');
|
|
document.querySelector(`.author-container[data-login="${login}"]`).classList.add('hover');
|
|
});
|
|
|
|
element.addEventListener('mouseleave', function () {
|
|
const login = this.getAttribute('data-login');
|
|
document.querySelector(`.author-container[data-login="${login}"]`).classList.remove('hover');
|
|
});
|
|
});
|
|
}
|
|
repoCards.forEach((element, index) => {
|
|
renderCard(element, index);
|
|
});
|
|
})
|