Hugo: Add XML as a support data format

Created on 4 Mar 2018  路  11Comments  路  Source: gohugoio/hugo

It would be nice to provide XML as an available data type to load.

Currently, Hugo accepts, TOML, YAML, JSON, and CSV. Is there any reason why XML is NOT amongst the available formats?

It would be great to add XML as an available data type for the /data folder.

Enhancement Keep

Most helpful comment

Having a getXML similar to getJSON would be useful in creating "planets" from feeds. Ref: https://discourse.gohugo.io/t/anyone-here-interested-in-a-hugo-planet/15092.

It would be great to add XML as an available data type for the /data folder.

Not just the data/ folder, my proposal is to allow remote XML fetching. Once RSS/ATOM feeds can be fetched, we can maintain theme components that do the parsing of the fetched XML feeds.

All 11 comments

@bzerangue This would be fantastic. Not sure if something like https://github.com/beevik/etree would help said efforts...

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

+1 on this. Type "XML" could then act as a flag to invoke DOCTYPE parsing and optional validation.

Having a getXML similar to getJSON would be useful in creating "planets" from feeds. Ref: https://discourse.gohugo.io/t/anyone-here-interested-in-a-hugo-planet/15092.

It would be great to add XML as an available data type for the /data folder.

Not just the data/ folder, my proposal is to allow remote XML fetching. Once RSS/ATOM feeds can be fetched, we can maintain theme components that do the parsing of the fetched XML feeds.

This looks promising: https://github.com/clbanning/mxj

But note that mapping arbitrary XML into a map isn't trivial.

This'll be great for surfacing RSS from other sources like Medium

+1 from me, too - I'd like to be able to include references from the RFC index, but it's only published in XML format.

I'm working on a Go library to parse mixed content. If anyone can propose an API (i.e. interfaces) that would be useful for Hugo, I could give it a whack.

On the RSS specific side, I currently leverage a site that parses RSS to JSON for consumption

{{ $rssJ := getJSON "https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fmedium.com%2Ffeed%2Fnightingale-hq" }}


{{ range $rssJ.items }}
    {{ $post := . }}
    <div class="col-12 col-md-6 col-lg-4 mb-2 mr-2 pb-8 blog" style="background-image: url({{ $post.thumbnail }});">
    <a href="{{ $post.link }}" target="_blank" alt="{{ $post.title }}">
    <h2>{{ $post.title }}</h2>
    </a>
    <h3>{{ $post.author }}</h3>
    </div>
{{ end }}

If this request is too complex as is, what about simplifying it to a getRSS function? I know for me the need for getXML is simply so that I can have Hugo read in RSS feeds.

Agreed, this would be fantastic. From the library tech perspective -- we are experimenting with using Hugo to generate Special Collections Finding Aids from Encoded Archival Description (EAD) -- an XML format widely used by libraries.

Was this page helpful?
0 / 5 - 0 ratings