summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-09-22 15:15:16 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-09-24 11:54:29 +0200
commitef0e7149d63c64269b852cf68a2af67b94b8eec3 (patch)
tree7182a4d3e396d231a3c62c4ca76055eb3ba3a845 /common
parentc32094ace113412abea354b7119d154168097287 (diff)
Add $image.Process
Which supports all the existing actions: resize, crop, fit, fill. But it also allows plain format conversions: ``` {{ $img = $img.Process "webp" }} ``` Which will be a simple re-encoding of the source image. Fixes #11483
Diffstat (limited to 'common')
-rw-r--r--common/hstrings/strings.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/common/hstrings/strings.go b/common/hstrings/strings.go
index 2fd791f43..88df97607 100644
--- a/common/hstrings/strings.go
+++ b/common/hstrings/strings.go
@@ -99,3 +99,26 @@ var reCache = regexpCache{re: make(map[string]*regexp.Regexp)}
func GetOrCompileRegexp(pattern string) (re *regexp.Regexp, err error) {
return reCache.getOrCompileRegexp(pattern)
}
+
+// InSlice checks if a string is an element of a slice of strings
+// and returns a boolean value.
+func InSlice(arr []string, el string) bool {
+ for _, v := range arr {
+ if v == el {
+ return true
+ }
+ }
+ return false
+}
+
+// InSlicEqualFold checks if a string is an element of a slice of strings
+// and returns a boolean value.
+// It uses strings.EqualFold to compare.
+func InSlicEqualFold(arr []string, el string) bool {
+ for _, v := range arr {
+ if strings.EqualFold(v, el) {
+ return true
+ }
+ }
+ return false
+}