SVG Title Script
The svg-title.js script normalizes the <title> tags inside each icon. These tags improve accessibility and screen-reader context while enforcing AWS’s naming requirements.
Purpose and Standards
AWS mandates that each icon maintain the full “AWS” or “Amazon” prefix in any user-facing label. While filenames can omit these for developer clarity, internal metadata like SVG <title> must remain compliant.
This script ensures all icons include a readable, human-friendly title that corresponds to the visual name, without any legacy clutter or brand prefix removal.
How It Works
- Traverses all files in the target icon directory (default:
aws-icons/). - Reads SVG content and extracts the
<title>tag. - Strips prefixes, sizes, and duplicates using logic inherited from
rename.js. - Overwrites only when the title differs from the cleaned version.
Cleaning Logic
The title cleaning strategy mirrors the rename script, but retains essential brand prefixes and avoids impacting filenames. It uses simple regex cleanup to remove suffixes and preserve readability.
function cleanTitle(raw) {
let s = raw;
if (s.includes("/")) s = s.split("/").pop();
s = s.replace(/^(?:Arch_|Res_)/i, "");
s = s.replace(/_\d+$/i, "");
s = s.replace(/__+/g, "_");
s = s.replace(/^[-_]+|[-_]+$/g, "");
return s || raw;
}
This ensures titles are readable and consistent while maintaining the original branding context.
Regex Replacement
Titles are matched and replaced with a single pass. No external libraries are used, keeping the script dependency-free.
const rx = /<title>([\s\S]*?)<\/title>/i;
const m = data.match(rx);
if (!m) return; // skip if missing
const cleaned = cleanTitle(m[1].trim());
const updated = data.replace(rx, `<title>${cleaned}</title>`);
CLI Options
--rootdefines the input directory (default:aws-icons).--dry-runprints differences without saving changes.
This command is best used after renaming, ensuring metadata alignment. It produces legible output and avoids false diffs from inconsistent casing or hidden prefixes.