From d39a64afe17662fb7ec6e108c323c3654d384adc Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Fri, 20 Jun 2025 22:15:27 +0800 Subject: [PATCH] refactor(repo-card): use iife and async loading --- assets/js/fetch-repo.js | 6 ++---- layouts/shortcodes/codeberg.html | 1 + layouts/shortcodes/forgejo.html | 1 + layouts/shortcodes/gitea.html | 1 + layouts/shortcodes/github.html | 1 + layouts/shortcodes/gitlab.html | 1 + 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/assets/js/fetch-repo.js b/assets/js/fetch-repo.js index b47678ae..41ee97fb 100644 --- a/assets/js/fetch-repo.js +++ b/assets/js/fetch-repo.js @@ -1,4 +1,4 @@ -async function fetchRepo() { +(async () => { const script = document.currentScript; const repoURL = script?.getAttribute("data-repo-url"); const repoId = script?.getAttribute("data-repo-id"); @@ -54,6 +54,4 @@ async function fetchRepo() { } catch (error) { console.error(error); } -} - -fetchRepo(); +})(); diff --git a/layouts/shortcodes/codeberg.html b/layouts/shortcodes/codeberg.html index 15faea91..0fa21e78 100644 --- a/layouts/shortcodes/codeberg.html +++ b/layouts/shortcodes/codeberg.html @@ -52,6 +52,7 @@ {{ $fetchRepo := resources.Get "js/fetch-repo.js" }} {{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }}