Can Hugo transform geojson?

The file is remote and I want to build pages from data with it.

Process it like any JSON.

 error calling Unmarshal: MIME "text/plain" not supported

Are you accessing the data remotely? If so…

  1. What is the file extension in the URL?
  2. What is the content-type in the response header?

I understand the desire for privacy, but an example URL would save both of us some time.

Here’s the server’s response when downloading the .geojson file from the URL provided via DM:

image

The content-type is wrong. The server should respond with application/geo+json.

https://datatracker.ietf.org/doc/html/rfc7946#section-12

I can get around this by explicitly unmarshaling .Content (line 7 below):

{{ $data := "" }}
{{ $url := "https://example.org/foo.geojson" }}
{{ with resources.GetRemote $url }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ else }}
    {{ $data = .Content | transform.Unmarshal }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get remote resource %q" $url }}
{{ end }}

<pre>{{ jsonify (dict "indent" "  ") $data }}</pre>

I think I will update the examples in the docs to explicitly unmarshal .Content. That will handle cases where transform.Unmarshal rejects the resource because its media type is not a known serialization format.

Docs changed with https://github.com/gohugoio/hugoDocs/pull/2444.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.