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 IsLicenceFile ¶ added in v0.1.2
IsLicenceFile reports whether a root-level filename names a licence or notice.
func LicenceFiles ¶ added in v0.1.2
LicenceFiles lists the licence and notice files directly under root, as absolute paths in a stable order. Subdirectories are not searched: a licence file deep in an upstream tree usually belongs to a dependency or a fixture, not to the icons.
func SlugifyGroup ¶
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 ¶
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 ¶
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) Name ¶
func (Categorise) Name() string
type FindLicences ¶ added in v0.1.2
type FindLicences struct {
pipeline.TransformKind
}
FindLicences records the upstream's own licence files, before anything narrows the tree.
Upstreams keep LICENSE, NOTICE and the like at the root of the package or archive, while the icons sit in a subdirectory that SubsetTo or FlattenVariants then makes the fetched path. Run after either and the licence is already out of reach, which is how every pack came to ship its icons without the text MIT, ISC, Apache-2.0, BSD and OFL require to travel with them. So this runs first, looks only at the root, and hands the paths forward for the LicenceTexts sink. It reads nothing and changes nothing.
func (FindLicences) Execute ¶ added in v0.1.2
func (FindLicences) Execute(ctx *pipeline.Context) error
func (FindLicences) Name ¶ added in v0.1.2
func (FindLicences) 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) 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.
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.
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.
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.
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.