min

package
v0.0.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MediatypeJPEG = "image/jpeg"
	MediatypeWebP = "image/webp"
	MediatypeSVG  = "image/svg+xml"
)

Mediatypes de las tres codificaciones que este paquete produce.

Variables

This section is empty.

Functions

func DefaultCacheDir added in v0.0.22

func DefaultCacheDir(rootDir string) (string, error)

DefaultCacheDir es dónde guardar las conversiones de un proyecto cuando la salida NO es un entregable: un directorio por proyecto bajo el caché del usuario, nunca dentro del proyecto.

La conversión es cara y merece caché entre arranques; lo que no merece es que esa caché viva dentro del repositorio del usuario, donde se confunde con la salida publicable del sitio.

func ExpectedExt added in v0.0.20

func ExpectedExt(srcPath string) string

ExpectedExt is the extension ProcessImage will write for src — the single answer the whole pipeline asks, so that "is this output current?" and "is this output an orphan?" cannot disagree with what the encoder actually produces. Treating both extensions as equally valid is what let a lossless .webp written by an older release survive next to the .jpg that replaced it: each variant appeared up to date because SOME file matched, and cleanup spared the stale one because SOME asset could have claimed it.

A JPEG source needs no decode: the format has no alpha channel, so it is opaque by construction. Anything else has to be read. An unreadable source returns "", meaning "unknown" — callers then fall back to accepting either extension rather than deleting output they cannot reason about.

func IsUpToDate

func IsUpToDate(srcPath string, variants image.Variant, outputDir string) bool

func IsVector added in v0.0.21

func IsVector(srcPath string) bool

IsVector responde si la fuente se entrega tal cual en vez de codificarse.

Existe porque un logo vectorial no tiene dónde vivir en un pipeline que solo sabía convertir mapas de bits: quedaba fuera de image.Asset y cada sitio se escribía su propio copiador de archivos. Ese copiador era invisible para el demonio, así que el mismo proyecto servía el logo en release y devolvía 404 en desarrollo.

func ProcessImage

func ProcessImage(src ParsedAsset, outputDir string, quality int, log func(...any)) ([]string, error)

func VectorOutputName added in v0.0.21

func VectorOutputName(srcPath string) string

VectorOutputName es el nombre con el que un vector aterriza en la salida: el suyo, sin sufijo de variante. La página lo referencia por ese nombre.

Types

type Artifact added in v0.0.22

type Artifact struct {
	Path      string
	Mediatype string
	Content   []byte
}

Artifact es una imagen ya procesada, lista para servirse o para escribirse. Path es la ruta relativa a la raíz del sitio y ES la URL: "img/foto.M.jpg".

type Config

type Config struct {
	RootDir   string
	OutputDir string
	Quality   int
}

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func New

func New(c *Config) *Handler

func (*Handler) Artifacts added in v0.0.22

func (h *Handler) Artifacts() []Artifact

Artifacts devuelve el contenido de cada imagen producida por el último LoadImages/ReloadModule.

Existe porque el consumidor de desarrollo sirve el sitio desde memoria. Sin esto, la única forma de servir una imagen era que este paquete la dejara en un directorio dentro del proyecto del usuario, y ese directorio pasaba a ser una segunda salida del sitio que nadie pidió.

Un origen cuya salida no se puede leer se omite en silencio: no es un error del consumidor, y el log ya reportó el fallo de conversión.

func (*Handler) LoadImages

func (h *Handler) LoadImages() error

LoadImages discovers modules via go list and processes their images.

func (*Handler) Logger

func (h *Handler) Logger(messages ...any)

func (*Handler) Name

func (h *Handler) Name() string

func (*Handler) ReloadModule

func (h *Handler) ReloadModule(moduleDir string) error

ReloadModule re-extracts and re-processes images for a single module.

func (*Handler) SetFinder added in v0.0.6

func (h *Handler) SetFinder(f *modfind.Finder)

func (*Handler) SetLog

func (h *Handler) SetLog(fn func(messages ...any))

func (*Handler) UnobservedFiles

func (h *Handler) UnobservedFiles() []string

type ParsedAsset

type ParsedAsset struct {
	AbsPath  string        // absolute path: moduleDir + "/" + asset.Path
	Variants image.Variant // resolved bitmask value
	Alt      string
	BaseName string // base name without extension: "logo", "hero"
}

func ExtractImages

func ExtractImages(moduleDir string) ([]ParsedAsset, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL