Understanding `.MediaType` suffixes

I’m sorry if this question is not solely about Hugo but I figure maybe someone can help me here.

I’m testdriving Page Resources’ .MediaType and I’m confused about the .Suffixes method.

It systematically returns a slice containing one file extension.

  • icon.svg, image/svg+xml > svg
  • file.pdf, application/pdf > pdf
  • other.old.pdf, application/pdf > pdf

In what case could this return more than one string of suffix/extension ?

Thanks

In the case where you define more than one suffix.

In my first naive implementation of this, I quickly scanned the MIME type spec and didn’t really understand the suffix term used there.

So, image/svg+xml – the suffix is xml (in the MIME definition), but that is hardly ever the file suffix.

So I had to redo the whole … thing.

So suffixes = a list of file suffixes (without the separator (usually a “.”, but that can be set).

All of the built-in media types in Hugo has only 1. But you can add more if you want to, say, support both “json” and “jsn” for application/json.

These suffixes have two practical uses (currently):

  • Used to identify a MIME type by the suffix in resources.Get etc.
  • It’s registered as a MIME type for that extension in the hugo server

Relevant PR/discussion:

Thank you so much to both of you!