transforms

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package transforms mutates the in-flight asset tree between a source and a sink. Every transform reads and writes Context.FetchedPath.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SlugifyGroup

func SlugifyGroup(group string) string

SlugifyGroup slugs a CLDR group name.

Python has two near-copies of this -- categorise's replaces "&" with a space and then spaces with hyphens, indexer's only does the first. They produce identical output for every CLDR group because SlugifyName already collapses any run of non-alphanumerics to a single hyphen, so the second replace is redundant. One function here, rather than two that are equal by luck.

func SlugifyName

func SlugifyName(name string) string

SlugifyName is the shared name-to-slug rule, exported because the CLDR categoriser and the indexer both need it and must agree.

Types

type CLDRRecord

type CLDRRecord struct {
	Codepoints []string
	Group      string
	Name       string
}

CLDRRecord is one fully-qualified emoji from Unicode's emoji-test.txt.

func ParseCLDR

func ParseCLDR(text string) []CLDRRecord

ParseCLDR reads emoji-test.txt into records, carrying the group heading forward across the rows beneath it.

func (CLDRRecord) Key

func (r CLDRRecord) Key() string

Key is the codepoint sequence as it appears in an upstream filename.

type Categorise

type Categorise struct {
	pipeline.TransformKind

	// By is "cldr" or "passthrough".
	By  string
	Log *slog.Logger
}

Categorise regroups a flat emoji tree into Unicode CLDR category directories, renaming each file to the emoji's slug.

Upstream ships one flat directory named by codepoint; the packs file icons under a category so a picker can group them. Requires a UnicodeCldr source to have populated the taxonomy first.

func (Categorise) Execute

func (t Categorise) Execute(ctx *pipeline.Context) error

func (Categorise) Name

func (Categorise) Name() string

type FlattenVariants

type FlattenVariants struct {
	pipeline.TransformKind

	// Variants are the directories to merge. Order is irrelevant to the
	// result and the output is written deterministically regardless.
	Variants []Variant

	// Separator normalises the character upstream puts between words, when
	// the pack spells them differently. `_` and a space are rewritten to it.
	//
	// google-material-design-icons needs this and the other two do not:
	// upstream ships `18_up_rating`, the pack committed `18-up-rating`, and
	// without the rewrite only 607 of 2168 names in each variant line up.
	Separator string
}

FlattenVariants merges several upstream directories into one flat tree, distinguishing them by an affix on each filename.

Some packs vendor a multi-directory upstream as a single flat set, and a manifest path cannot express that: SubsetTo picks one directory, so pointing it at heroicons' `24/solid` would refresh a quarter of the set and the sink would delete the other three quarters. Measured, those sets are not approximations of one variant but exact merges of all of them --

heroicons      1288 = 324 o- + 324 s- + 324 m- + 316 c-, a perfect round trip
teeny-icons    1200 = 600 bare + 600 -o, likewise
gmdi          10610 of 10751 committed, the remainder retired upstream

-- so the rule is recoverable exactly rather than being a guess about what the pack maintainer once did by hand.

func (FlattenVariants) Execute

func (t FlattenVariants) Execute(ctx *pipeline.Context) error

func (FlattenVariants) Name

func (FlattenVariants) Name() string

type Indexer

type Indexer struct {
	pipeline.TransformKind

	// Targets is any of "codepoints" and "names".
	Targets []string

	// OutDirKey names an Extras key holding the output directory. When empty
	// or absent, the files land beside the fetched tree.
	OutDirKey string
}

Indexer writes the lookup files a picker needs beside the icons.

func (Indexer) Execute

func (t Indexer) Execute(ctx *pipeline.Context) error

func (Indexer) Name

func (Indexer) Name() string

type Sanitise

type Sanitise struct {
	pipeline.TransformKind

	// AlsoStripClass removes the class attribute as well. Off by default.
	AlsoStripClass bool

	// Strict turns policy violations into a failure. Off by default, because
	// an upstream that ships one odd icon should not block the other 6,000 --
	// the violation is reported either way.
	Strict bool

	// ReportOnly counts what the policy would remove without writing anything.
	//
	// For the aggregator pack, which has never been sanitised: its committed
	// icons keep comments the policy strips, including fontawesome's licence
	// attribution, so enforcing the policy during a refresh would rewrite tens
	// of thousands of files and discard that attribution. Measured, all 50
	// fontawesome icons sampled change under the policy. Reporting keeps the
	// security picture visible without turning a refresh into a rewrite; the
	// decision to enforce is then someone's to take deliberately.
	ReportOnly bool

	Log *slog.Logger
}

Sanitise applies the SVG policy to every file in the tree, in place.

func (Sanitise) Execute

func (t Sanitise) Execute(ctx *pipeline.Context) error

func (Sanitise) Name

func (Sanitise) Name() string

type Slugify

type Slugify struct{ pipeline.TransformKind }

Slugify lowercases and hyphenates SVG filenames in place.

Not used by either shipped recipe -- both upstreams already ship slugged names -- but kept because a new pack from a less tidy upstream is exactly when it is needed, and it is four lines.

func (Slugify) Execute

func (Slugify) Execute(ctx *pipeline.Context) error

func (Slugify) Name

func (Slugify) Name() string

type SubsetTo

type SubsetTo struct {
	pipeline.TransformKind
	Subdir string
}

SubsetTo re-points FetchedPath at a subdirectory of the fetched tree.

This is how a source's `source_path` is honoured: npm ships @tabler/icons with the SVGs under icons/, and the rest of the tarball is not wanted.

func (SubsetTo) Execute

func (t SubsetTo) Execute(ctx *pipeline.Context) error

func (SubsetTo) Name

func (SubsetTo) Name() string

type Variant

type Variant struct {
	// Subdir is the directory inside the fetched tree.
	Subdir string

	// Prefix and Suffix are applied to the file stem. A variant carrying
	// neither is the unmarked one -- heroicons marks all four, while
	// teenyicons leaves `solid` bare and suffixes only `outline`.
	Prefix string
	Suffix string
}

Variant is one upstream directory contributing to a flattened set, and the affix that distinguishes its icons from the other variants' once they share a directory.

Jump to

Keyboard shortcuts

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