6a22cfbece0a — Ted Unangst 15 days ago
convert avif option
2 files changed, 7 insertions(+), 1 deletions(-)

M main.go
M web.go
M main.go +2 -0
@@ 50,6 50,7 @@ var serverMsg template.HTML
 var aboutMsg template.HTML
 var loginMsg template.HTML
 var collectForwards = true
+var convertAVIF = false
 
 func serverURL(u string, args ...interface{}) string {
 	return fmt.Sprintf("https://"+serverName+u, args...)

          
@@ 185,6 186,7 @@ func main() {
 	getconfig("honkwindow", &honkwindow)
 	honkwindow *= 24 * time.Hour
 	getconfig("collectforwards", &collectForwards)
+	getconfig("convertavif", &convertAVIF)
 
 	prepareStatements(db)
 

          
M web.go +5 -1
@@ 1559,7 1559,11 @@ func (d *Donk) HTML() template.HTML {
 		if d.Media == "text/plain" || d.Media == "application/pdf" {
 			return templates.Sprintf(`<p><a href="/d/%s">Attachment: %s</a>%s (%d)</p>`, d.XID, d.Name, desc, d.Meta.Length)
 		} else {
-			return templates.Sprintf(`<picture><source type="image/fiva" srcset="/d/%s.avif"><img class="donk donklink" src="/d/%s" loading=lazy title="%s" alt="%s" width="%d" height="%d"></picture>`, d.XID, d.XID, d.Desc, d.Desc, d.Meta.Width, d.Meta.Height)
+			var sources template.HTML
+			if convertAVIF && d.Media == "image/jpeg" {
+				sources += templates.Sprintf(`<source type="image/avif" srcset="/d/%s.avif">`, d.XID)
+			}
+			return templates.Sprintf(`<picture>%s<img class="donk donklink" src="/d/%s" loading=lazy title="%s" alt="%s" width="%d" height="%d"></picture>`, sources, d.XID, d.Desc, d.Desc, d.Meta.Width, d.Meta.Height)
 		}
 	} else {
 		if d.External {