chore(repo-card): add try statement at GetRemote

This commit is contained in:
ZhenShuo Leo
2025-07-17 23:09:00 +08:00
parent 237c90afa9
commit ecf6d1d53f
6 changed files with 54 additions and 6 deletions
+11 -1
View File
@@ -1,6 +1,16 @@
{{ $id := delimit (slice "forgejo" (partial "functions/uid.html" .)) "-" }}
{{- $forgejoURL := print (.Get "server" | default .Site.Params.forgejoDefaultServer) "/api/v1/repos/" (.Get "repo") -}}
{{- $forgejoData := resources.GetRemote $forgejoURL | transform.Unmarshal -}}
{{- $forgejoData := dict -}}
{{- with try (resources.GetRemote $forgejoURL) -}}
{{- with .Err -}}
{{- warnf "forgejo shortcode: failed to fetch remote resource from %q: %s" $forgejoURL .Position -}}
{{- else with .Value -}}
{{- $forgejoData = . | transform.Unmarshal -}}
{{- else -}}
{{- warnf "forgejo shortcode: unable to get remote resource from %q: %s" $forgejoURL .Position -}}
{{- end -}}
{{- end -}}
{{- with $forgejoData -}}
<div class="forgejo-card-wrapper">
<a id="{{ $id }}" target="_blank" href="{{ .html_url }}" class="cursor-pointer">