class

Hwaro::Services::UnusedAssets

Inherits Reference < Object

Constants

ASSET_EXTENSIONS = Set {".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp", ".avif", ".ico", ".bmp", ".tiff", ".tif", ".css", ".js", ".woff", ".woff2", ".ttf", ".eot", ".otf", ".mp4", ".webm", ".ogg", ".mp3", ".wav", ".pdf", ".zip"}
CONTENT_EXTENSIONS = Set {".md", ".markdown"}
DATA_SCAN_EXTENSIONS = ["yml", "yaml", "json", "toml"] of ::String

Data and translation sources that can name an asset (logo: /img/a.png in data/site.yml, an icon path in i18n/en.toml). data/ is loaded by Phases::Initialize#load_data_files with exactly this extension set, and i18n locale files are TOML; templates render whatever those hold, so a path that only ever appears there is still in use.

IMPLICIT_ROOT_ASSET = /\A(?:favicon\.ico|apple-touch-icon(?:-precomposed)?(?:-\d+x\d+)?\.png)\z/i

Files browsers request by a well-known root URL with no markup reference (/favicon.ico, /apple-touch-icon[-precomposed][-WxH].png), so the textual scan can never see them used.

STATIC_SCAN_EXTENSIONS = ["css", "scss", "sass", "js", "json", "webmanifest", "xml", "svg", "txt", "html", "htm"] of ::String

Static sources that reference other static files: Sass (@font-face / url() in a .scss that compiles to .css), PWA manifests (site.webmanifest icons), and <image href> inside an SVG.

html/htm belong here too. Hand-written pages under static/ are copied into the output verbatim by the build, so an <img src=...> inside one is a fully static, literal reference — yet without the extension the scan never read the file and reported its images as unused, which --delete then removed (real data loss).

TEMPLATE_SCAN_EXTENSIONS = ["html", "j2", "jinja", "jinja2", "ecr", "css", "js", "xml", "json", "webmanifest", "svg", "txt"] of ::String

Template files that may reference an asset. .html alone was not enough: Builder::TEMPLATE_EXTENSION_REGEX also accepts .j2, .jinja, .jinja2 and .ecr, and feed/manifest templates are authored as rss.xml.jinja / site.webmanifest. Anything missing here is invisible to the reference scan, so its assets are reported unused — and --delete removes files the build still needs.

Constructors

new(content_dir : String = "content", static_dir : String = "static", templates_dir : String = "templates", templates_dir_explicit : Bool = false, static_dir_explicit : Bool = false)
Source

Class methods

boundary_referenced?(scanned_text : String, basename : String) : Bool

Boundary-anchored literal check backing the safety net above. A class method so it stays testable on filesystems (APFS) that refuse to create non-UTF-8 filenames at all. A basename that is not valid UTF-8 cannot become a PCRE2 pattern — Regex.new raises ArgumentError — so it is reported as not-referenced here without raising; run skips (and warns about) such assets before this check is reached.

Source

Instance methods

delete_unused(files : Array(String))
Source