Skip to content

Commit 6a180a8

Browse files
committed
Update deprecated code
- data.GetJSON -> resources.Get with transform.Unmarshal - See https://gohugo.io/functions/transform/unmarshal/#unmarshal-a-resource
1 parent 8b5cb76 commit 6a180a8

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

layouts/shortcodes/ghrelease-live.html

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@
1616
{{- $id = . -}}
1717
{{ end }}
1818

19+
{{- $release := dict -}}
1920
{{- $url := (printf "https://api.github.com/repos/%s/%s/releases/%s" $user $repo $tag) -}}
20-
{{- $release := getJSON $url -}}
21+
{{ with resources.GetRemote $url }}
22+
{{ with .Err }}
23+
{{ errorf "%s" . }}
24+
{{ else }}
25+
{{ $data = . | transform.Unmarshal }}
26+
{{ end }}
27+
{{ else }}
28+
{{ errorf "Unable to get remote resource %q" $url }}
29+
{{ end }}
2130

2231
{{- with (index $release.assets $id) -}}
2332
{{ $p := . }}

layouts/shortcodes/ghrelease.html

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616
{{- $id = . -}}
1717
{{ end }}
1818

19-
{{- $url := (printf "https://api.github.com/repos/%s/%s/releases/%s" $user $repo $tag) -}}
20-
{{- $url := "data/ghrelease.json" -}}
21-
{{- $release := getJSON $url -}}
19+
{{- $release := dict -}}
20+
{{- $path := "data/ghrelease.json" -}}
21+
{{- with resources.Get $path -}}
22+
{{- with . | transform.Unmarshal -}}
23+
{{- $release = . -}}
24+
{{- end -}}
25+
{{- else -}}
26+
{{ errorf "Unable to get global resource %q" $path }}
27+
{{- end -}}
2228

2329
{{- with (index $release.assets $id) -}}
24-
{{ $p := . }}
30+
{{- $p := . -}}
2531
{{- if eq $data "file_name" -}}
2632
{{- $p.name -}}
2733
{{- else if eq $data "file_size" -}}

0 commit comments

Comments
 (0)