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,8 +1,17 @@
{{ $id := delimit (slice "github" (partial "functions/uid.html" .)) "-" }}
{{- $githubURL := print "https://api.github.com/repos/" (.Get "repo") -}}
{{- $githubData := resources.GetRemote $githubURL | transform.Unmarshal -}}
{{- $githubThumbnailURL := print "https://opengraph.githubassets.com/0/" (.Get "repo") -}}
{{- $showThumbnail := .Get "showThumbnail" | default true -}}
{{- $githubData := dict -}}
{{- with try (resources.GetRemote $githubURL) -}}
{{- with .Err -}}
{{- warnf "github shortcode: failed to fetch remote resource from %q: %s" $githubURL .Position -}}
{{- else with .Value -}}
{{- $githubData = . | transform.Unmarshal -}}
{{- else -}}
{{- warnf "github shortcode: unable to get remote resource from %q: %s" $githubURL .Position -}}
{{- end -}}
{{- end -}}
{{- with $githubData -}}
<div class="github-card-wrapper">