Skip to content

Commit

Permalink
Update deprecated code
Browse files Browse the repository at this point in the history
- data.GetJSON -> resources.Get with transform.Unmarshal
- See https://gohugo.io/functions/transform/unmarshal/#unmarshal-a-resource
  • Loading branch information
martignoni committed Oct 16, 2024
1 parent 8b5cb76 commit 6a180a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 10 additions & 1 deletion layouts/shortcodes/ghrelease-live.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@
{{- $id = . -}}
{{ end }}

{{- $release := dict -}}
{{- $url := (printf "https://api.github.com/repos/%s/%s/releases/%s" $user $repo $tag) -}}
{{- $release := getJSON $url -}}
{{ with resources.GetRemote $url }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ $data = . | transform.Unmarshal }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}

{{- with (index $release.assets $id) -}}
{{ $p := . }}
Expand Down
14 changes: 10 additions & 4 deletions layouts/shortcodes/ghrelease.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
{{- $id = . -}}
{{ end }}

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

{{- with (index $release.assets $id) -}}
{{ $p := . }}
{{- $p := . -}}
{{- if eq $data "file_name" -}}
{{- $p.name -}}
{{- else if eq $data "file_size" -}}
Expand Down

0 comments on commit 6a180a8

Please sign in to comment.