1
0
Fork 0
hugo/docs/layouts/partials/helpers/funcs/get-remote-data.html

25 lines
664 B
HTML

{{/* prettier-ignore-start */ -}}
{{/*
Parses the serialized data from the given URL and returns a map or an array.
Supports CSV, JSON, TOML, YAML, and XML.
@param {string} . The URL from which to retrieve the serialized data.
@returns {any}
@example {{ partial "get-remote-data.html" "https://example.org/foo.json" }}
*/}}
{{/* prettier-ignore-end */ -}}
{{ $url := . }}
{{ $data := dict }}
{{ with try (resources.GetRemote $url) }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else with .Value }}
{{ $data = .Content | transform.Unmarshal }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ end }}
{{ end }}
{{ return $data }}