Only add image files to imageBox files slice (#2017)

* Only add image files to `imageBox` files slice
* Update Changelog
This commit is contained in:
peolic
2021-11-17 02:58:49 +02:00
committed by GitHub
parent 89c7c022f6
commit 955083882e
3 changed files with 29 additions and 4 deletions

View File

@@ -17,14 +17,31 @@ type imageBox struct {
files []string
}
var imageExtensions = []string{
".jpg",
".jpeg",
".png",
".gif",
".svg",
".webp",
}
func newImageBox(box fs.FS) (*imageBox, error) {
ret := &imageBox{
box: box,
}
err := fs.WalkDir(box, ".", func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() {
ret.files = append(ret.files, path)
if d.IsDir() {
return nil
}
baseName := strings.ToLower(d.Name())
for _, ext := range imageExtensions {
if strings.HasSuffix(baseName, ext) {
ret.files = append(ret.files, path)
break
}
}
return nil