Skip to content
quarry Artifact [63cc7fec0e]
Login

Artifact [63cc7fec0e]

Artifact 63cc7fec0eef9687a2949d0e037e617fadd89ab9d7fcc64ccdb9651f07d06117:


package web

import (
	"crypto/sha256"
	_ "embed"
	"encoding/hex"
	"strings"

	"craftdesign.group/quarry/internal/api"
)

// The badge Gmail shows in place of the wordmark text: the mark and the
// ZEITFORGE wordmark (FORGE in the muted brown) in cream on the mark's
// dark tile, rendered from the same outlines the header inlines, at 2x
// of the two sizes the header (92x28) and the footer (59x18) show. It
// reads in both of Gmail's modes, neither of which reports dark to the
// message.
//
//go:embed assets/badge.png
var badgePNG []byte

//go:embed assets/badge-sm.png
var badgeSmPNG []byte

// AssetVersion is the short content hash of an image a message refers to,
// by site path ("/apple-touch-icon.png", "/badge.png", "/icons/x.png"). A
// mail client caches an image by its URL, so the URL has to change when
// the bytes do. "" for a path with no such image.
func AssetVersion(path string) string {
	var b []byte
	switch {
	case path == "/apple-touch-icon.png":
		b = appleTouchIcon
	case path == "/badge.png":
		b = badgePNG
	case path == "/badge-sm.png":
		b = badgeSmPNG
	case strings.HasPrefix(path, "/icons/"):
		b, _ = refIcons.ReadFile("assets/icons/" + strings.TrimPrefix(path, "/icons/"))
	}
	if b == nil {
		return ""
	}
	sum := sha256.Sum256(b)
	return hex.EncodeToString(sum[:])[:8]
}

func init() { api.AssetVersion = AssetVersion }