.Resources.ByType "video" return empty

I’d like to get a video file by .Resources.ByType "video". I have read the discussion before and I found that type video had been supported.

But in the same folder, there are 1.mp4 and 2.jpg. I can get 2.jpg by .Resources.ByType "image", but can not get 1.mp4 by .Resources.ByType "video" because the return value is an empty array.

I also look at mediaType.go, which shows that .mp4 is supported.

And I can not find why this happens.


Updates

After more tests, I found that video can be accessed by using its suffix. For example, I can access 1.mp4 by .Resources.ByType "mp4", and access 1.webm by .Resources.ByType "webm". But none of these can be accessed by .Resources.ByType "video".

But for images, I can use .Resources.ByType "image" to access it. If I use .Resources.ByType "png", the result will be empty, which is totally contradictory to videos.

This conflicting situation makes me feel very confused.

It’s not video, it’s video/formattype

See Resources.ByType for video files?

This PR happened right after your link and mine: https://github.com/gohugoio/hugo/pull/6431

video/mp4 does not work as well.

And for images, I can use image to get all images in any formats.

So I think there might be some other reasons?

I think it says video/mpeg for all mp* formats. Did not test recently. Maybe “image” has a special fallback for all formats…

Look at this PR, the subtype is (in my opinion) what is matched against (not sure if you end up at the right point with this link, let’s try):

I just tested video/mpeg, which also did not work as well.

Really confusing…

1 Like

It even says mp4 in that PR. I overlooked that.

Can you post a sample repo with one of the files and how you try to implement it? Maybe something else is wrong.

I just use {{ print (.Resources.ByType "video") }} which returns empty array. And in the same folder I have another jpg image. When I use {{ print (.Resources.ByType "image") }}, the result is right.

This is only a one line usage, but if you still think it is necessary to post a sample I can make one. Thank you for your fast reply!

After more tests, I found that video can be accessed by using its suffix. For example, I can access 1.mp4 by .Resources.ByType "mp4" , and access 1.webm by .Resources.ByType "webm" . But none of these can be accessed by .Resources.ByType "video" .

But for images, I can use .Resources.ByType "image" to access it. If I use .Resources.ByType "png" , the result will be empty, which is totally contradictory to videos.

This conflicting situation makes me feel very confused.

You can open a GitHub issue on the main Hugo repository with a request for a new method .Resources.ByType "video"

Thank you! I will open an issue about this.

For reference the associated issue can be found at:

Anyone who wishes to participate in the discussion they can do so on GitHub.