From 00d19cfb415b6f1ad38aefe51052d76b1277370f Mon Sep 17 00:00:00 2001 From: noeFly Date: Sat, 21 Jun 2025 23:03:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=BE=A9=E4=BD=9C=E8=80=85?= =?UTF-8?q?=E9=A0=AD=E8=B2=BC=E9=A1=AF=E7=A4=BA=20refactor:=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E6=8E=88=E6=AC=8A=E6=A2=9D=E6=AC=BE=E8=88=87=E7=A8=8B?= =?UTF-8?q?=E5=BC=8F=E8=AA=9E=E8=A8=80=E9=A1=AF=E7=A4=BA=20-=20=E5=9B=A0?= =?UTF-8?q?=E7=82=BA=20GitLab=20API=20=E4=B8=AD=E4=B8=A6=E7=84=A1=E6=AD=A4?= =?UTF-8?q?=E8=B3=87=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/rehype-component-gitlab-card.mjs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/plugins/rehype-component-gitlab-card.mjs b/src/plugins/rehype-component-gitlab-card.mjs index 1fc68f4..0a0aa9b 100644 --- a/src/plugins/rehype-component-gitlab-card.mjs +++ b/src/plugins/rehype-component-gitlab-card.mjs @@ -27,11 +27,6 @@ export function GitlabCardComponent(properties, children) { const cardUuid = `GC${Math.random().toString(36).slice(-6)}`; // Collisions are not important const nAvatar = h(`div#${cardUuid}-avatar`, { class: "gc-avatar" }); - // const nLanguage = h( - // `span#${cardUuid}-language`, - // { class: "gc-language" }, - // "Waiting...", - // ); const nTitle = h("div", { class: "gc-titlebar" }, [ h("div", { class: "gc-titlebar-left" }, [ @@ -40,7 +35,7 @@ export function GitlabCardComponent(properties, children) { h("div", { class: "gc-user" }, repo.split("/")[0]), ]), h("div", { class: "gc-divider" }, "/"), - h("div", { class: "gc-repo" }, repo.split("/")[1]), + h("div", { class: `gc-repo ${cardUuid}-repo` }, repo.split("/")[1]), ]), h("div", { class: "github-logo" }), ]); @@ -53,24 +48,21 @@ export function GitlabCardComponent(properties, children) { const nStars = h(`div#${cardUuid}-stars`, { class: "gc-stars" }, "00K"); const nForks = h(`div#${cardUuid}-forks`, { class: "gc-forks" }, "0K"); - // const nLicense = h(`div#${cardUuid}-license`, { class: "gc-license" }, "0K"); - - console.log(`https://gitlab.com/api/v4/projects/${repoE}`); const nScript = h( `script#${cardUuid}-script`, { type: "text/javascript", defer: true }, ` - fetch('https://gitlab.com/api/v4/projects/${repoE}', { referrerPolicy: "no-referrer" }).then(response => response.json()).then(data => { + fetch('https://gitlab.com/api/v4/projects/${repoE}').then(response => response.json()).then(data => { console.log(data); + document.getElementsByClassName('${cardUuid}-repo')[0].innerText = data.name; document.getElementById('${cardUuid}-description').innerText = data.description?.replace(/:[a-zA-Z0-9_]+:/g, '') || "Description not set"; - document.getElementById('${cardUuid}-language').innerText = data.language; + // document.getElementById('${cardUuid}-language').innerText = data.language; document.getElementById('${cardUuid}-forks').innerText = Intl.NumberFormat('en-us', { notation: "compact", maximumFractionDigits: 1 }).format(data.forks_count).replaceAll("\u202f", ''); document.getElementById('${cardUuid}-stars').innerText = Intl.NumberFormat('en-us', { notation: "compact", maximumFractionDigits: 1 }).format(data.star_count).replaceAll("\u202f", ''); const avatarEl = document.getElementById('${cardUuid}-avatar'); - avatarEl.style.backgroundImage = 'url(' + data.owner.avatar_url + ')'; + avatarEl.style.backgroundImage = 'url(' + data.namespace.avatar_url + ')'; avatarEl.style.backgroundColor = 'transparent'; - // document.getElementById('${cardUuid}-license').innerText = data.license?.spdx_id || "no-license"; document.getElementById('${cardUuid}-card').classList.remove("fetch-waiting"); console.log("[GITLAB-CARD] Loaded card for ${repo} | ${cardUuid}.") }).catch(err => {