diff --git a/docs/javascripts/cookbooks-card.js b/docs/javascripts/cookbooks-card.js index dd36eacb..67f81edc 100644 --- a/docs/javascripts/cookbooks-card.js +++ b/docs/javascripts/cookbooks-card.js @@ -1,26 +1,51 @@ - document.addEventListener("DOMContentLoaded", function () { - async function setCard(el, url, name, desc, labels, version, theme, authors) { + 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", + "#22c55e", + "#14b8a6", + "#ef4444", + "#eab308", + "#8b5cf6", + "#f97316", + "#3b82f6", ] - let labelHTML = '' - if (labels) { - const labelArray = labels.split(',').map((label, index) => { - const color = colorList[index % colorList.length] - return `${label}` - }) + 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)]; - labelHTML = labelArray.join(' ') - } + const labelToColor = uniqueLabels.reduce((map, label, index) => { + map[label] = colorList[index % colorList.length]; + return map; + }, {}); + + + async function renderCard(element, elementIndex) { + const url = element.getAttribute('data-url'); + 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 ` + + ${label.trim()} + + `; + }).join(' ') : ''; const authorArray = authors.split(','); const authorDataArray = await Promise.all(authorArray.map(async (author) => { @@ -28,36 +53,51 @@ document.addEventListener("DOMContentLoaded", function () { return await response.json(); })); - let authorHTML = ''; - authorDataArray.forEach((authorData, index) => { - const marginLeft = index === 0 ? '0' : '-15px'; - authorHTML += ` -
+ let authorAvatarsHTML = authorDataArray.map((authorData, index) => { + const marginLeft = index === 0 ? '0' : '-10px'; + const zIndex = 100 - index; + return ` + `; - }); + }).join(''); - document.querySelectorAll('.author-container').forEach((container) => { - const tooltip = container.querySelector('.tooltip'); - container.addEventListener('mouseover', () => { - tooltip.style.visibility = 'visible'; - tooltip.style.opacity = '1'; - }); - container.addEventListener('mouseout', () => { - tooltip.style.visibility = 'hidden'; - tooltip.style.opacity = '0'; - }); - }); + let authorNamesHTML = authorDataArray.map( + authorData => ` + ` + ).join(', '); + let authorsHTML = ` + + `; - - el.innerText = ` + element.innerText = `