diff options
Diffstat (limited to 'echo/tplfuncs/picture_tag.go')
-rw-r--r-- | echo/tplfuncs/picture_tag.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/echo/tplfuncs/picture_tag.go b/echo/tplfuncs/picture_tag.go new file mode 100644 index 0000000..ddec4aa --- /dev/null +++ b/echo/tplfuncs/picture_tag.go | |||
@@ -0,0 +1,16 @@ | |||
1 | package tplfuncs | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "html/template" | ||
6 | ) | ||
7 | |||
8 | // RenderPictureTag renders a picture tag with a webp and jpeg source | ||
9 | // and alt text. | ||
10 | func RenderPictureTag(img, alt string) template.HTML { | ||
11 | return template.HTML(fmt.Sprintf(`<picture> | ||
12 | <source srcset="%s.webp" type="image/webp" /> | ||
13 | <source srcset="%s.jpg" type="image/jpeg" /> | ||
14 | <img src="%s.jpg" alt="%s" loading="lazy" /> | ||
15 | </picture>`, img, img, img, alt)) | ||
16 | } | ||