fix: failed GitHub API requests no longer break the href of repo card & style tweak

This commit is contained in:
saicaca 2024-07-20 23:24:19 +08:00
parent f438ea4252
commit bd4f0e8b63
2 changed files with 4 additions and 6 deletions

View File

@ -441,23 +441,22 @@ const className = Astro.props.class;
opacity: 0.7
transition: opacity 0.15s ease-in-out
.gc-description, .gc-infobar
.gc-description, .gc-infobar, .gc-avatar
background-color: var(--tw-prose-body)
color: transparent
opacity: 0.5;
border-radius: 0.5rem
animation: pulsate 2s infinite linear
user-select: none
&:before
background-color: transparent
.gc-avatar
display: none
.gc-repo
margin-left: -0.1rem
.gc-description, .gc-infobar
border-radius: 0.5rem
a.card-github.fetch-error
pointer-events: all
opacity: 1

View File

@ -78,7 +78,6 @@ 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}-card').href = data.html_url;
document.getElementById('${cardUuid}-description').innerText = data.description.replace(/:[a-zA-Z0-9_]+:/g, '');
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", '');