diff --git a/docs/javascripts/cookbooks-card.js b/docs/javascripts/cookbooks-card.js index d2447324..c1798337 100644 --- a/docs/javascripts/cookbooks-card.js +++ b/docs/javascripts/cookbooks-card.js @@ -1,26 +1,37 @@ - document.addEventListener("DOMContentLoaded", function () { - async function setCard(el, url, name, 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}` - }) + async function renderCard(element) { + 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'); - labelHTML = labelArray.join(' ') - } + const labelHTML = labels ? labels.split(',').map((label, index) => { + const color = colorList[index % colorList.length]; + return ` + + ${label.trim()} + + `; + }).join(' ') : ''; const authorArray = authors.split(','); const authorDataArray = await Promise.all(authorArray.map(async (author) => { @@ -32,16 +43,33 @@ document.addEventListener("DOMContentLoaded", function () { const marginLeft = index === 0 ? '0' : '-10px'; const zIndex = 100 - index; return ` -
- - ${authorData.login}'s avatar +
+ + ${authorData.login}'s avatar
`; }).join(''); let authorNamesHTML = authorDataArray.map( - authorData => ` + authorData => ` + ${authorData.login} @@ -55,7 +83,21 @@ document.addEventListener("DOMContentLoaded", function () {
`; - el.innerText = ` + 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 = `
@@ -79,22 +121,10 @@ document.addEventListener("DOMContentLoaded", function () { ` - let sanitizedHTML = DOMPurify.sanitize(el.innerText); - el.innerHTML = sanitizedHTML; - } - for (const el of document.querySelectorAll('.repo-card')) { - const url = el.getAttribute('data-url'); - const name = el.getAttribute('data-name'); - const labels = el.getAttribute('data-labels'); - const version = el.getAttribute('data-version'); - const authors = el.getAttribute('data-author'); - const palette = __md_get("__palette") - if (palette && typeof palette.color === "object") { - var theme = palette.color.scheme === "slate" ? "dark-theme" : "light-default" - } else { - var theme = "light-default" - } - - setCard(el, url, name, labels, version, theme, authors); + let sanitizedHTML = DOMPurify.sanitize(element.innerText); + element.innerHTML = sanitizedHTML; } + document.querySelectorAll('.repo-card').forEach((element, index) => { + renderCard(element); + }); }) diff --git a/docs/stylesheets/cookbooks-card.css b/docs/stylesheets/cookbooks-card.css index f794f498..13199793 100644 --- a/docs/stylesheets/cookbooks-card.css +++ b/docs/stylesheets/cookbooks-card.css @@ -61,6 +61,10 @@ transition: transform 0.2s; } +.author-container.hover { + transform: translateY(-0.125rem); +} + .author-container:hover { transform: translateY(-0.125rem); } @@ -88,6 +92,13 @@ text-decoration: underline; /* Adds underline on hover */ } +.label { + color: #fff; + padding: 2px 4px; + border-radius: 4px; + margin-right: 4px; +} + .non-selectable-text { -webkit-user-select: none; /* Safari */ -moz-user-select: none; /* Firefox */ diff --git a/docs/theme/cookbooks.html b/docs/theme/cookbooks.html index 0446c5d2..dc22da68 100644 --- a/docs/theme/cookbooks.html +++ b/docs/theme/cookbooks.html @@ -11,8 +11,9 @@

Supervision Cookbooks

-

-

+

+

+