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,5 +1,5 @@
[module]
[module.hugoVersion]
extended = true
min = "0.137.0"
min = "0.141.0"
max = "0.148.0"

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">

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">

View File

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

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">

View File

@@ -1,7 +1,16 @@
{{ $id := delimit (slice "gitlab" (partial "functions/uid.html" .)) "-" }}
{{- $gitlabURL := print (default "https://gitlab.com/" (.Get "baseURL")) "api/v4/projects/" (.Get "projectID") -}}
{{- $gitLabData := dict -}}
{{- with try (resources.GetRemote $gitlabURL) -}}
{{- with .Err -}}
{{- warnf "gitlab shortcode: failed to fetch remote resource from %q: %s" $gitlabURL .Position -}}
{{- else with .Value -}}
{{- $gitLabData = . | transform.Unmarshal -}}
{{- else -}}
{{- warnf "gitlab shortcode: unable to get remote resource from %q: %s" $gitlabURL .Position -}}
{{- end -}}
{{- end -}}
{{- $gitLabData := resources.GetRemote $gitlabURL | transform.Unmarshal -}}
{{- with $gitLabData -}}
<div class="gitlab-card-wrapper">
<a id="{{ $id }}" target="_blank" href="{{ .web_url }}" class="cursor-pointer">