@@ -59,28 +59,20 @@ export function GithubCardComponent(properties, children) {
59
59
{ type : 'text/javascript' , defer : true } ,
60
60
`
61
61
fetch('https://api.github.com/repos/${ repo } ', { referrerPolicy: "no-referrer" }).then(response => response.json()).then(data => {
62
- if (data.description) {
63
- document.getElementById('${ cardUuid } -description').innerText = data.description.replace(/:[a-zA-Z0-9_]+:/g, '');
64
- } else {
65
- document.getElementById('${ cardUuid } -description').innerText = "Description not set"
66
- }
62
+ document.getElementById('${ cardUuid } -description').innerText = data.description?.replace(/:[a-zA-Z0-9_]+:/g, '') || "Description not set";
67
63
document.getElementById('${ cardUuid } -language').innerText = data.language;
68
64
document.getElementById('${ cardUuid } -forks').innerText = Intl.NumberFormat('en-us', { notation: "compact", maximumFractionDigits: 1 }).format(data.forks).replaceAll("\u202f", '');
69
65
document.getElementById('${ cardUuid } -stars').innerText = Intl.NumberFormat('en-us', { notation: "compact", maximumFractionDigits: 1 }).format(data.stargazers_count).replaceAll("\u202f", '');
70
66
const avatarEl = document.getElementById('${ cardUuid } -avatar');
71
67
avatarEl.style.backgroundImage = 'url(' + data.owner.avatar_url + ')';
72
68
avatarEl.style.backgroundColor = 'transparent';
73
- if (data.license?.spdx_id) {
74
- document.getElementById('${ cardUuid } -license').innerText = data.license?.spdx_id
75
- } else {
76
- document.getElementById('${ cardUuid } -license').innerText = "no-license"
77
- };
78
- document.getElementById('${ cardUuid } -card').classList.remove("fetch-waiting");
79
- console.log("[GITHUB-CARD] Loaded card for ${ repo } | ${ cardUuid } .")
69
+ document.getElementById('${ cardUuid } -license').innerText = data.license?.spdx_id || "no-license";
70
+ document.getElementById('${ cardUuid } -card').classList.remove("fetch-waiting");
71
+ console.log("[GITHUB-CARD] Loaded card for ${ repo } | ${ cardUuid } .")
80
72
}).catch(err => {
81
73
const c = document.getElementById('${ cardUuid } -card');
82
- c.classList.add("fetch-error");
83
- console.warn("[GITHUB-CARD] (Error) Loading card for ${ repo } | ${ cardUuid } .")
74
+ c? .classList.add("fetch-error");
75
+ console.warn("[GITHUB-CARD] (Error) Loading card for ${ repo } | ${ cardUuid } .")
84
76
})
85
77
` ,
86
78
)
0 commit comments