automatic image class
This commit is contained in:
parent
be0867d3fa
commit
b282eecc58
2 changed files with 17 additions and 5 deletions
|
|
@ -1,3 +0,0 @@
|
|||
//go:generate templ generate
|
||||
|
||||
package html
|
||||
|
|
@ -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 }/>
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue