From 4ff3d07d30b9dde9fa65830fb6ce1beb36d9dd18 Mon Sep 17 00:00:00 2001 From: Served Smart <195884188+servedsmart@users.noreply.github.com> Date: Thu, 5 Jun 2025 16:05:22 +0200 Subject: [PATCH] :art: structure: Use more explicit naming in fetchRepo() --- assets/js/fetch-repo.js | 12 ++++++------ layouts/shortcodes/codeberg.html | 2 +- layouts/shortcodes/forgejo.html | 2 +- layouts/shortcodes/gitea.html | 2 +- layouts/shortcodes/github.html | 2 +- layouts/shortcodes/gitlab.html | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/assets/js/fetch-repo.js b/assets/js/fetch-repo.js index c7ad744e..689b1e96 100644 --- a/assets/js/fetch-repo.js +++ b/assets/js/fetch-repo.js @@ -1,9 +1,9 @@ function fetchRepo() { - const script = document.currentScript; - const repoURL = script && script.getAttribute("data-url") ? script.getAttribute("data-url") - : (console.error("data-url is null"), null); - const repoId = script && script.getAttribute("data-id") ? script.getAttribute("data-id") - : (console.error("data-id is null"), null); + const scriptElement = document.currentScript; + const repoURL = scriptElement && scriptElement.getAttribute("data-repo-url") ? scriptElement.getAttribute("data-repo-url") + : (console.error("data-repo-url is null"), null); + const repoId = scriptElement && scriptElement.getAttribute("data-repo-id") ? scriptElement.getAttribute("data-repo-id") + : (console.error("data-repo-id is null"), null); const requestObjects = repoId.startsWith("github") ? ["full_name", "description", "stargazers_count", "forks"] : repoId.startsWith("gitlab") ? ["name_with_namespace", "description", "star_count", "forks_count"] @@ -21,7 +21,7 @@ function fetchRepo() { element = document.getElementById(`${repoId}-stargazers`); } element ? (element.innerHTML = data[requestObject]) - : (console.error(`element.innerHTML for '${repoId}-${requestObject}' is null`), null); + : (console.error(`Element '${repoId}-${requestObject}' not found`), null); }); }) .catch((error) => console.error(error)); diff --git a/layouts/shortcodes/codeberg.html b/layouts/shortcodes/codeberg.html index 13763044..4f9a251c 100644 --- a/layouts/shortcodes/codeberg.html +++ b/layouts/shortcodes/codeberg.html @@ -51,7 +51,7 @@ {{ $fetchRepo := resources.Get "js/fetch-repo.js" }} {{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} - + {{- end -}} diff --git a/layouts/shortcodes/forgejo.html b/layouts/shortcodes/forgejo.html index 21c61354..2424fd9a 100644 --- a/layouts/shortcodes/forgejo.html +++ b/layouts/shortcodes/forgejo.html @@ -51,7 +51,7 @@ {{ $fetchRepo := resources.Get "js/fetch-repo.js" }} {{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} - + {{- end -}} diff --git a/layouts/shortcodes/gitea.html b/layouts/shortcodes/gitea.html index 30dd6162..79418776 100644 --- a/layouts/shortcodes/gitea.html +++ b/layouts/shortcodes/gitea.html @@ -51,7 +51,7 @@ {{ $fetchRepo := resources.Get "js/fetch-repo.js" }} {{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} - + {{- end -}} diff --git a/layouts/shortcodes/github.html b/layouts/shortcodes/github.html index dfcfaf36..0d471898 100644 --- a/layouts/shortcodes/github.html +++ b/layouts/shortcodes/github.html @@ -67,7 +67,7 @@ {{ $fetchRepo := resources.Get "js/fetch-repo.js" }} {{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} - + {{- end -}} diff --git a/layouts/shortcodes/gitlab.html b/layouts/shortcodes/gitlab.html index 2467f9e0..e7b9d9fe 100644 --- a/layouts/shortcodes/gitlab.html +++ b/layouts/shortcodes/gitlab.html @@ -41,7 +41,7 @@ {{ $fetchRepo := resources.Get "js/fetch-repo.js" }} {{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} - + {{- end -}}