image thumbnails
This commit is contained in:
parent
640e9a2d0c
commit
26d81e7c64
210 changed files with 28 additions and 5 deletions
|
|
@ -7,7 +7,7 @@ templ Album(images []string, activePage string, pages []string) {
|
|||
<div id="album-grid">
|
||||
for _, img := range images {
|
||||
<div tabindex="0" role="button" aria-label={ img }>
|
||||
@AvifImage("album/"+img, img, true)
|
||||
@AvifAlbumImage("album/"+img, img)
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"piekarnikgosi/utils"
|
||||
)
|
||||
|
||||
|
|
@ -24,6 +26,26 @@ func processImage(fileName string) string {
|
|||
return "/" + dst[4:]
|
||||
}
|
||||
|
||||
func thumbnailPath(fullPath string) string {
|
||||
ext := filepath.Ext(fullPath)
|
||||
return fullPath[:len(fullPath)-len(ext)] + "_thumb.avif"
|
||||
}
|
||||
|
||||
templ AvifAlbumImage(srcPath, alt string) {
|
||||
<img src={ processImage(albumImageSrc(srcPath)) }
|
||||
data-fullsrc={ processImage(srcPath) }
|
||||
alt={ alt }
|
||||
loading="lazy" />
|
||||
}
|
||||
|
||||
func albumImageSrc(srcPath string) string {
|
||||
thumb := thumbnailPath(srcPath)
|
||||
if _, err := os.Stat("img/" + thumb); err == nil {
|
||||
return thumb
|
||||
}
|
||||
return srcPath
|
||||
}
|
||||
|
||||
templ AvifImage(srcPath, alt string, lazy bool) {
|
||||
<img src={ processImage(srcPath) } alt={ alt }
|
||||
if lazy {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue