mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 07:12:52 +01:00
fix: Switch page error when fetch fails (#304)
Some checks failed
Code quality / quality (push) Failing after 3s
Build and Check / Astro Check for Node.js 22 (push) Failing after 3s
Build and Check / Astro Check for Node.js 23 (push) Failing after 4s
Build and Check / Astro Build for Node.js 22 (push) Failing after 3s
Build and Check / Astro Build for Node.js 23 (push) Failing after 4s
Some checks failed
Code quality / quality (push) Failing after 3s
Build and Check / Astro Check for Node.js 22 (push) Failing after 3s
Build and Check / Astro Check for Node.js 23 (push) Failing after 4s
Build and Check / Astro Build for Node.js 22 (push) Failing after 3s
Build and Check / Astro Build for Node.js 23 (push) Failing after 4s
This commit is contained in:
@@ -59,28 +59,20 @@ 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 => {
|
||||
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}-description').innerText = data.description?.replace(/:[a-zA-Z0-9_]+:/g, '') || "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", '');
|
||||
const avatarEl = document.getElementById('${cardUuid}-avatar');
|
||||
avatarEl.style.backgroundImage = 'url(' + data.owner.avatar_url + ')';
|
||||
avatarEl.style.backgroundColor = 'transparent';
|
||||
if (data.license?.spdx_id) {
|
||||
document.getElementById('${cardUuid}-license').innerText = data.license?.spdx_id
|
||||
} else {
|
||||
document.getElementById('${cardUuid}-license').innerText = "no-license"
|
||||
};
|
||||
document.getElementById('${cardUuid}-card').classList.remove("fetch-waiting");
|
||||
console.log("[GITHUB-CARD] Loaded card for ${repo} | ${cardUuid}.")
|
||||
document.getElementById('${cardUuid}-license').innerText = data.license?.spdx_id || "no-license";
|
||||
document.getElementById('${cardUuid}-card').classList.remove("fetch-waiting");
|
||||
console.log("[GITHUB-CARD] Loaded card for ${repo} | ${cardUuid}.")
|
||||
}).catch(err => {
|
||||
const c = document.getElementById('${cardUuid}-card');
|
||||
c.classList.add("fetch-error");
|
||||
console.warn("[GITHUB-CARD] (Error) Loading card for ${repo} | ${cardUuid}.")
|
||||
c?.classList.add("fetch-error");
|
||||
console.warn("[GITHUB-CARD] (Error) Loading card for ${repo} | ${cardUuid}.")
|
||||
})
|
||||
`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user