automatic image class

This commit is contained in:
bronkuu 2026-06-09 16:04:04 +02:00
parent be0867d3fa
commit b282eecc58
2 changed files with 17 additions and 5 deletions

View file

@ -1,3 +0,0 @@
//go:generate templ generate
package html

View file

@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/hex"
"log"
"strings"
"piekarnikgosi/utils"
)
@ -14,7 +15,7 @@ func imageSrcDst(input string) (src, dst string) {
return src, dst
}
func ProcessImage(fileName string) string {
func processImage(fileName string) string {
dst, err := utils.CopyIfNotExists(imageSrcDst(fileName))
if err != nil {
@ -24,6 +25,20 @@ func ProcessImage(fileName string) string {
return dst[4:]
}
func stripSize(path string) string {
if strings.Contains(path, "wide") {
return "wide"
}
if strings.Contains(path, "tall") {
return "tall"
}
if strings.Contains(path, "large") {
return "large"
}
return ""
}
templ AvifImage(srcPath, alt string) {
<img class="wide" src={ ProcessImage(srcPath) } alt={ alt }/>
<img class={stripSize(srcPath)} src={ processImage(srcPath) } alt={ alt }/>
}