mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
tpl/reflect: Make the IsImageResource implementation less technical
And closer to the documentation. The old one was correct, but a bit too tied to the internal implementation.
This commit is contained in:
@@ -58,7 +58,8 @@ var (
|
||||
".webp": WEBP,
|
||||
}
|
||||
|
||||
imageFormatsBySubType = map[string]Format{
|
||||
// These are the image types we can process.
|
||||
processableImageSubTypes = map[string]Format{
|
||||
media.Builtin.JPEGType.SubType: JPEG,
|
||||
media.Builtin.PNGType.SubType: PNG,
|
||||
media.Builtin.TIFFType.SubType: TIFF,
|
||||
@@ -123,7 +124,7 @@ func ImageFormatFromExt(ext string) (Format, bool) {
|
||||
}
|
||||
|
||||
func ImageFormatFromMediaSubType(sub string) (Format, bool) {
|
||||
f, found := imageFormatsBySubType[sub]
|
||||
f, found := processableImageSubTypes[sub]
|
||||
return f, found
|
||||
}
|
||||
|
||||
|
||||
@@ -402,12 +402,16 @@ func (r *resourceAdapter) getImageOps() images.ImageResourceOps {
|
||||
|
||||
// IsImage reports whether the given resource is an image that can be processed.
|
||||
func IsImage(v any) bool {
|
||||
r, ok := v.(*resourceAdapter)
|
||||
if ok {
|
||||
_, ok := r.target.(images.ImageResourceOps)
|
||||
return ok
|
||||
r, ok := v.(resource.Resource)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
mt := r.MediaType()
|
||||
if mt.MainType != "image" {
|
||||
return false
|
||||
}
|
||||
_, isImage := images.ImageFormatFromMediaSubType(mt.SubType)
|
||||
return isImage
|
||||
}
|
||||
|
||||
func (r *resourceAdapter) publish() {
|
||||
|
||||
Reference in New Issue
Block a user