36 lines
643 B
Text
36 lines
643 B
Text
package html
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"log"
|
|
"piekarnikgosi/utils"
|
|
)
|
|
|
|
func imageSrcDst(input string) (src, dst string) {
|
|
src = "img/" + input
|
|
hash := sha256.Sum256([]byte(input))
|
|
dst = "www/images/" + hex.EncodeToString(hash[:])[:16] + ".avif"
|
|
return src, dst
|
|
}
|
|
|
|
func processImage(fileName string) string {
|
|
dst, err := utils.CopyIfNotExists(imageSrcDst(fileName))
|
|
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
return dst[4:]
|
|
}
|
|
|
|
templ AvifImage(srcPath, alt string, lazy bool, priority bool) {
|
|
<img src={ processImage(srcPath) } alt={ alt }
|
|
if lazy {
|
|
loading="lazy"
|
|
}
|
|
if priority {
|
|
fetchpriority="high"
|
|
}
|
|
/>
|
|
}
|