|
| 1 | + |
| 2 | +document.addEventListener("DOMContentLoaded", function () { |
| 3 | + |
| 4 | + async function setCard(el, name, desc, labels, version, theme, authors) { |
| 5 | + const colorList = [ |
| 6 | + "A351FB", "FF4040", "FFA1A0", "FF7633", "FFB633", "D1D435", "4CFB12", |
| 7 | + "94CF1A", "40DE8A", "1B9640", "00D6C1", "2E9CAA", "00C4FF", "364797", |
| 8 | + "6675FF", "0019EF", "863AFF", "530087", "CD3AFF", "FF97CA", "FF39C9" |
| 9 | + ] |
| 10 | + |
| 11 | + let labelHTML = '' |
| 12 | + if (labels) { |
| 13 | + const labelArray = labels.split(',').map((label, index) => { |
| 14 | + const color = colorList[index % colorList.length] |
| 15 | + return `<span style="background-color: #${color}; color: #fff; padding: 2px 6px; border-radius: 12px; margin-right: 4px;">${label}</span>` |
| 16 | + }) |
| 17 | + |
| 18 | + labelHTML = labelArray.join(' ') |
| 19 | + } |
| 20 | + |
| 21 | + const authorArray = authors.split(','); |
| 22 | + const authorDataArray = await Promise.all(authorArray.map(async (author) => { |
| 23 | + const response = await fetch(`https://api.github.com/users/${author.trim()}`); |
| 24 | + return await response.json(); |
| 25 | + })); |
| 26 | + |
| 27 | + let authorHTML = ''; |
| 28 | + authorDataArray.forEach((authorData, index) => { |
| 29 | + const marginLeft = index === 0 ? '0' : '-15px'; |
| 30 | + const backgroundColor = theme === 'light-default' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(255, 255, 255, 0.5)'; |
| 31 | + const textColor = theme === 'light-default' ? '#fff' : '#000'; |
| 32 | + authorHTML += ` |
| 33 | + <div class="author-container" style="display: inline-block; margin-left: ${marginLeft}; position: relative;"> |
| 34 | + <a href="https://github.com/${authorData.login}" target="_blank"> |
| 35 | + <img src="${authorData.avatar_url}" width="32" height="32" style="border-radius: 50%;" /> |
| 36 | + </a> |
| 37 | + <div class="tooltip" style="visibility: hidden; background-color: #555; color: #fff; text-align: center; border-radius: 6px; padding: 5px 0; position: absolute; z-index: 1; bottom: 125%; left: 50%; margin-left: -60px; opacity: 0; transition: opacity 0.3s; width: 120px;"> |
| 38 | + ${authorData.login} |
| 39 | + </div> |
| 40 | + </div> |
| 41 | + `; |
| 42 | + }); |
| 43 | + |
| 44 | + document.querySelectorAll('.author-container').forEach((container) => { |
| 45 | + const tooltip = container.querySelector('.tooltip'); |
| 46 | + container.addEventListener('mouseover', () => { |
| 47 | + tooltip.style.visibility = 'visible'; |
| 48 | + tooltip.style.opacity = '1'; |
| 49 | + }); |
| 50 | + container.addEventListener('mouseout', () => { |
| 51 | + tooltip.style.visibility = 'hidden'; |
| 52 | + tooltip.style.opacity = '0'; |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + el.innerText = ` |
| 59 | + <div style="flex-direction: column; height: 100%; display: flex; |
| 60 | + 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}"> |
| 61 | + <div style="display: flex; align-items: center;"> |
| 62 | + <i class="fa-solid:book-open" style="color: ${theme.color}; margin-right: 8px;"></i> |
| 63 | + <span style="font-weight: 600; color: ${theme.linkColor};"> |
| 64 | + <a style="text-decoration: none; color: inherit;" href="/notebooks/demo/">${name}</a> |
| 65 | + </span> |
| 66 | + </div> |
| 67 | + <div style="font-size: 12px; margin-bottom: 10px; margin-top: 8px; color: ${theme.color}; flex: 1;">${desc}</div> |
| 68 | + <div style="display: flex; align-items: center; justify-content: flex-start; margin-bottom: 8px;"> |
| 69 | + ${authorHTML} |
| 70 | + </div> |
| 71 | + <div style="font-size: 12px; color: ${theme.color}; display: flex; flex: 0;"> |
| 72 | + <div style="display: 'flex'; align-items: center; margin-right: 16px;"> |
| 73 | + </div> |
| 74 | + <div style="display: 'flex'; align-items: center; margin-right: 16px;"> |
| 75 | + <img src="/assets/supervision-lenny.png" aria-label="stars" width="16" height="16" role="img" /> |
| 76 | + <span>${version}</span> |
| 77 | + </div> |
| 78 | + <div style="display: 'flex'}; align-items: center;"> |
| 79 | + <span>${labelHTML}</span> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + ` |
| 84 | + |
| 85 | + let sanitizedHTML = DOMPurify.sanitize(el.innerText); |
| 86 | + el.innerHTML = sanitizedHTML; |
| 87 | + } |
| 88 | + const themes = { |
| 89 | + 'light-default': { |
| 90 | + background: 'white', |
| 91 | + borderColor: '#e1e4e8', |
| 92 | + color: '#586069', |
| 93 | + linkColor: '#0366d6', |
| 94 | + }, |
| 95 | + 'dark-theme': { |
| 96 | + background: '#1e2129', |
| 97 | + borderColor: '#607D8B', |
| 98 | + color: '#ECEFF1', |
| 99 | + linkColor: '#9E9E9E', |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + for (const el of document.querySelectorAll('.repo-card')) { |
| 104 | + const name = el.getAttribute('data-name'); |
| 105 | + const desc = el.getAttribute('data-desc'); |
| 106 | + const labels = el.getAttribute('data-labels'); |
| 107 | + const version = el.getAttribute('data-version'); |
| 108 | + const authors = el.getAttribute('data-author'); |
| 109 | + const palette = __md_get("__palette") |
| 110 | + if (palette && typeof palette.color === "object") { |
| 111 | + var theme = palette.color.scheme === "slate" ? "dark-theme" : "light-default" |
| 112 | + } else { |
| 113 | + var theme = "light-default" |
| 114 | + } |
| 115 | + |
| 116 | + setCard(el, name, desc, labels, version, theme, authors); |
| 117 | + } |
| 118 | +}) |
0 commit comments