From 856c2bb2c05b4d421cebe32f89931523bdd95c93 Mon Sep 17 00:00:00 2001 From: pawarherschel <93267442+pawarherschel@users.noreply.github.com> Date: Fri, 23 Aug 2024 18:33:59 +0530 Subject: [PATCH] fix: fix GitHub repo card not loading with empty description (#154) --- src/plugins/rehype-component-github-card.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/rehype-component-github-card.mjs b/src/plugins/rehype-component-github-card.mjs index dcca93d..b212a3a 100644 --- a/src/plugins/rehype-component-github-card.mjs +++ b/src/plugins/rehype-component-github-card.mjs @@ -59,7 +59,11 @@ export function GithubCardComponent(properties, children) { { type: 'text/javascript', defer: true }, ` fetch('https://api.github.com/repos/${repo}', { referrerPolicy: "no-referrer" }).then(response => response.json()).then(data => { - document.getElementById('${cardUuid}-description').innerText = data.description.replace(/:[a-zA-Z0-9_]+:/g, ''); + if (data.description) { + document.getElementById('${cardUuid}-description').innerText = data.description.replace(/:[a-zA-Z0-9_]+:/g, ''); + } else { + document.getElementById('${cardUuid}-description').innerText = "Description not set" + } document.getElementById('${cardUuid}-language').innerText = data.language; document.getElementById('${cardUuid}-forks').innerText = Intl.NumberFormat('en-us', { notation: "compact", maximumFractionDigits: 1 }).format(data.forks).replaceAll("\u202f", ''); document.getElementById('${cardUuid}-stars').innerText = Intl.NumberFormat('en-us', { notation: "compact", maximumFractionDigits: 1 }).format(data.stargazers_count).replaceAll("\u202f", '');