mirror of
https://gitee.com/butubb8/blowfish.git
synced 2025-12-05 14:17:50 +08:00
🎨 structure: Use more explicit naming in fetchRepo()
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
</div>
|
||||
{{ $fetchRepo := resources.Get "js/fetch-repo.js" }}
|
||||
{{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }}
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-url="{{ $codebergURL }}" data-id="{{ $id }}"></script>
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-repo-url="{{ $codebergURL }}" data-repo-id="{{ $id }}"></script>
|
||||
</a>
|
||||
</div>
|
||||
{{- end -}}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
</div>
|
||||
{{ $fetchRepo := resources.Get "js/fetch-repo.js" }}
|
||||
{{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }}
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-url="{{ $forgejoURL }}" data-id="{{ $id }}"></script>
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-repo-url="{{ $forgejoURL }}" data-repo-id="{{ $id }}"></script>
|
||||
</a>
|
||||
</div>
|
||||
{{- end -}}
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
</div>
|
||||
{{ $fetchRepo := resources.Get "js/fetch-repo.js" }}
|
||||
{{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }}
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-url="{{ $giteaURL }}" data-id="{{ $id }}"></script>
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-repo-url="{{ $giteaURL }}" data-repo-id="{{ $id }}"></script>
|
||||
</a>
|
||||
</div>
|
||||
{{- end -}}
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
</div>
|
||||
{{ $fetchRepo := resources.Get "js/fetch-repo.js" }}
|
||||
{{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }}
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-url="{{ $githubURL }}" data-id="{{ $id }}"></script>
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-repo-url="{{ $githubURL }}" data-repo-id="{{ $id }}"></script>
|
||||
</a>
|
||||
{{- end -}}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
</div>
|
||||
{{ $fetchRepo := resources.Get "js/fetch-repo.js" }}
|
||||
{{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }}
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-url="{{ $gitlabURL }}" data-id="{{ $id }}"></script>
|
||||
<script type="text/javascript" src="{{ $fetchRepo.RelPermalink }}" integrity="{{ $fetchRepo.Data.Integrity }}" data-repo-url="{{ $gitlabURL }}" data-repo-id="{{ $id }}"></script>
|
||||
</a>
|
||||
</div>
|
||||
{{- end -}}
|
||||
|
||||
Reference in New Issue
Block a user