Documentation
¶
Overview ¶
Package assets validates and publishes visual assets (SVG card templates, logos) discovered by repository layout plugins.
Index ¶
- Constants
- Variables
- func Check(filename string, data []byte) error
- func DropURIs(vctm []byte, uris map[string]bool) ([]byte, error)
- func Filename(slug, key, ext string) string
- func IsPublishableExt(ext string) bool
- func Publish(srcDir, outputDir, org, slug string, logger *slog.Logger) []string
- func URL(baseURL, org, filename string) string
- func ValidateSVG(data []byte) error
Constants ¶
const MaxSVGSize = 2 << 20
MaxSVGSize is the largest SVG document accepted for publication.
Variables ¶
var Exts = []string{".svg", ".png", ".jpg", ".jpeg", ".webp"}
Exts are the file extensions published for an asset.
var Keys = []string{"svg_template", "svg_template_dark", "logo"}
Keys are the asset keys layout plugins use in DiscoveredCredential.Assets.
Functions ¶
func Check ¶
Check validates asset content for publication. SVG documents are checked with ValidateSVG; raster images are accepted by extension.
func DropURIs ¶
DropURIs removes every object whose "uri" is in uris from a VCTM document and prunes containers left empty (svg_templates, logo, simple, rendering). It returns the document unchanged when uris is empty.
func IsPublishableExt ¶
IsPublishableExt reports whether ext (with leading dot) is a published asset extension.
func Publish ¶
Publish copies the staged assets of one credential from srcDir to <outputDir>/<org>/, next to the credential's VCTM. Staged files are named <slug>-<key><ext> for the known keys and extensions. SVG files are validated again before they are written, and a file that would replace a credential format file keeps the format file. It returns the published file names.
func URL ¶
URL returns the absolute URL of a published asset: <baseURL>/<org>/<filename>. A trailing slash on baseURL is trimmed.
func ValidateSVG ¶
ValidateSVG checks that data is a well-formed SVG document that is safe to serve from the registry origin. It returns a descriptive error for the first violation found. The document is walked with the encoding/xml tokenizer, so the checks follow the parsed structure of the document.
Types ¶
This section is empty.