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

View File

@@ -1,6 +1,16 @@
{{ $id := delimit (slice "codeberg" (partial "functions/uid.html" .)) "-" }}
{{- $codebergURL := print "https://codeberg.org/api/v1/repos/" (.Get "repo") -}}
{{- $codebergData := resources.GetRemote $codebergURL | transform.Unmarshal -}}
{{- $codebergData := dict -}}
{{- with try (resources.GetRemote $codebergURL) -}}
{{- with .Err -}}
{{- warnf "codeberg shortcode: failed to fetch remote resource from %q: %s" $codebergURL .Position -}}
{{- else with .Value -}}
{{- $codebergData = . | transform.Unmarshal -}}
{{- else -}}
{{- warnf "codeberg shortcode: unable to get remote resource from %q: %s" $codebergURL .Position -}}
{{- end -}}
{{- end -}}
{{- with $codebergData -}}
<div class="codeberg-card-wrapper">
<a id="{{ $id }}" target="_blank" href="{{ .html_url }}" class="cursor-pointer">