mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
Merge commit 'b3d87dd0fd746f07f9afa6e6a2969aea41da6a38'
This commit is contained in:
24
docs/layouts/_partials/helpers/funcs/get-remote-data.html
Normal file
24
docs/layouts/_partials/helpers/funcs/get-remote-data.html
Normal file
@@ -0,0 +1,24 @@
|
||||
{{/* 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 }}
|
Reference in New Issue
Block a user