Resources.ByType for video files?

This

{{ $poster := ((.Page.Resources.ByType "image").GetMatch (printf "%s*" $src)) }}

works very well, but

{{ $video := ((.Page.Resources.ByType "video").GetMatch (printf "%s*" $src)) }}

returns nothing, even when video files are present. Any ideas?

Bonus point (didn’t find in the doc): what file types can be found by ByType?

I don’t think that "video" is a media type that is currently recognized by Hugo with .Page.Resources.ByType.

But you may get a video by using a glob to check for the file extension by using resources.Match/GetMatch/Get as described over here

1 Like

So, Type is the main value in the MIME type, e.g. image/png=> image…

So, by default, this is the list:

(we do fall back on Go’s MIME registry for the unknowns)

As you see, not much video in that list. But you can add or modify these MIME type definitions in your site configuration.

1 Like

Also, as discussed in another thead, if you know the file extensions you can do pattern matching.

This is what I did, and found a workaround missing video MIME types like this:

But I didn’t thought of adding new MIME types in config.

Thanks, didn’t think of this.

However, adding some basic video MIME types could be useful for generic videos shortcodes. Any chance a PR for this would be accepted?

It would if we could agree on the scope: The video format world seems even more confusing than images; and the current built-ins are more or less the formats that Hugo deals with on some level, so if we add video to the mix it should be the top 3 MIME types or something.

Indeed. I thought about those listed here:

Extension Description MIME type
.avi AVI: Audio Video Interleave video/x-msvideo
.mpeg MPEG Video video/mpeg
.ogv OGG video video/ogg
.webm WEBM video video/webm
.3gp 3GPP audio/video container video/3gpp

Yes, that looks reasonable. Also note they also need to be put into the DefaultMediaTypes slice below their definition.

1 Like