diff --git a/docs/javascripts/cookbooks-card.js b/docs/javascripts/cookbooks-card.js index c1798337..04d3c27a 100644 --- a/docs/javascripts/cookbooks-card.js +++ b/docs/javascripts/cookbooks-card.js @@ -14,15 +14,29 @@ document.addEventListener("DOMContentLoaded", function () { "#3b82f6", ] - async function renderCard(element) { + 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 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(',').map((label, index) => { - const color = colorList[index % colorList.length]; + const labelHTML = labels ? labels.split(',').filter(label => label !== '').map((label, index) => { + const color = labelToColor[label.trim()]; return ` ` @@ -83,20 +97,6 @@ document.addEventListener("DOMContentLoaded", function () { `; - document.querySelectorAll('.author-name').forEach(element => { - element.addEventListener('mouseenter', function() { - const login = this.getAttribute('data-login'); - console.log(login, "enter") - document.querySelector(`.author-container[data-login="${login}"]`).classList.add('hover'); - }); - - element.addEventListener('mouseleave', function() { - const login = this.getAttribute('data-login'); - console.log(login, "leave") - document.querySelector(`.author-container[data-login="${login}"]`).classList.remove('hover'); - }); - }); - element.innerText = `
${version}
-
+
${labelHTML}
@@ -123,8 +123,20 @@ document.addEventListener("DOMContentLoaded", function () { 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'); + }); + }); } - document.querySelectorAll('.repo-card').forEach((element, index) => { - renderCard(element); + repoCards.forEach((element, index) => { + renderCard(element, index); }); }) diff --git a/docs/stylesheets/cookbooks-card.css b/docs/stylesheets/cookbooks-card.css index 13199793..118c946c 100644 --- a/docs/stylesheets/cookbooks-card.css +++ b/docs/stylesheets/cookbooks-card.css @@ -94,7 +94,7 @@ .label { color: #fff; - padding: 2px 4px; + padding: 2px 6px; border-radius: 4px; margin-right: 4px; } diff --git a/docs/theme/cookbooks.html b/docs/theme/cookbooks.html index dc22da68..22186807 100644 --- a/docs/theme/cookbooks.html +++ b/docs/theme/cookbooks.html @@ -12,8 +12,6 @@

-

-