Skip to content

Commit 52fcba1

Browse files
committed
feat: change GithubCardComponent
1 parent d5f78c0 commit 52fcba1

File tree

4 files changed

+7
-44
lines changed

4 files changed

+7
-44
lines changed

astro.config.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import sitemap from "@astrojs/sitemap";
22
import svelte from "@astrojs/svelte";
33
import tailwind from "@astrojs/tailwind";
44
import swup from "@swup/astro";
5-
import partytown from '@astrojs/partytown';
65
import Compress from "astro-compress";
76
import icon from "astro-icon";
87
import { defineConfig } from "astro/config";
@@ -26,7 +25,6 @@ export default defineConfig({
2625
base: "personBlog",
2726
trailingSlash: "always",
2827
integrations: [
29-
partytown(),
3028
tailwind({
3129
nesting: true,
3230
}),

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
"svelte": "^5.5.3",
5656
"tailwindcss": "^3.4.17",
5757
"typescript": "^5.7.2",
58-
"unist-util-visit": "^5.0.0",
59-
"@astrojs/partytown": "2.1.3"
58+
"unist-util-visit": "^5.0.0"
6059
},
6160
"devDependencies": {
6261
"@astrojs/ts-plugin": "^1.10.4",

pnpm-lock.yaml

Lines changed: 0 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/rehype-component-github-card.mjs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,20 @@ export function GithubCardComponent(properties, children) {
5959
{ type: 'text/javascript', defer: true },
6060
`
6161
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";
6763
document.getElementById('${cardUuid}-language').innerText = data.language;
6864
document.getElementById('${cardUuid}-forks').innerText = Intl.NumberFormat('en-us', { notation: "compact", maximumFractionDigits: 1 }).format(data.forks).replaceAll("\u202f", '');
6965
document.getElementById('${cardUuid}-stars').innerText = Intl.NumberFormat('en-us', { notation: "compact", maximumFractionDigits: 1 }).format(data.stargazers_count).replaceAll("\u202f", '');
7066
const avatarEl = document.getElementById('${cardUuid}-avatar');
7167
avatarEl.style.backgroundImage = 'url(' + data.owner.avatar_url + ')';
7268
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}.")
8072
}).catch(err => {
8173
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}.")
8476
})
8577
`,
8678
)

0 commit comments

Comments
 (0)