feat: add github repository card extension feature

- remove astro-compress to improve build speed
- add target and rel attributes to footer links
- rename unocss opacity utility from 'opacity' to 'op'
- update PostList component's page logic from 'isTag' to 'isHome'
- create extend.css file for markdown extended features
- reorganize and sort styles in heti.css
- fix inline code wrapping issue
This commit is contained in:
radishzzz 2025-05-02 18:06:59 +01:00
parent 266e5833e6
commit 2ddae5631e
15 changed files with 407 additions and 479 deletions

View file

@ -0,0 +1,59 @@
<script>
function setupGithubCards() {
const githubCards = document.querySelectorAll('.gc-container')
if (githubCards.length === 0)
return
githubCards.forEach(async (card) => {
const repo = (card as HTMLElement).dataset.repo
if (!repo)
return
const avatarEl = card.querySelector('.gc-owner-avatar') as HTMLElement
const descEl = card.querySelector('.gc-repo-description') as HTMLElement
const starsEl = card.querySelector('.gc-stars-count') as HTMLElement
const forksEl = card.querySelector('.gc-forks-count') as HTMLElement
const licenseEl = card.querySelector('.gc-license-info') as HTMLElement
try {
const response = await fetch(`https://api.github.com/repos/${repo}`)
if (response.ok) {
const data = await response.json()
if (avatarEl && data.owner?.avatar_url)
avatarEl.style.backgroundImage = `url(${data.owner.avatar_url})`
if (descEl && data.description)
descEl.textContent = data.description
if (starsEl) {
starsEl.textContent = new Intl.NumberFormat('en', {
notation: 'compact',
maximumFractionDigits: 1,
}).format(data.stargazers_count)
}
if (forksEl) {
forksEl.textContent = new Intl.NumberFormat('en', {
notation: 'compact',
maximumFractionDigits: 1,
}).format(data.forks_count)
}
if (licenseEl)
licenseEl.textContent = data.license?.spdx_id || 'No License'
}
else {
if (descEl)
descEl.textContent = 'Loading failed.'
}
}
catch {
console.error(`Failed to fetch ${repo}`)
}
})
}
setupGithubCards()
document.addEventListener('astro:page-load', setupGithubCards)
</script>