From 3a4cddc0c062e3beb71d39a71ab7de407783f977 Mon Sep 17 00:00:00 2001 From: Yann Date: Fri, 24 Jul 2026 10:04:18 -0700 Subject: [PATCH] fix single-word avatar initials getInitials doubled the first letter of a one-word name, so "Yann" rendered as "YY" on the blog index cards. With one name, names[0] and names[names.length - 1] are the same element; the length <= 2 early return only covered strings of two characters or fewer. Single-word names now yield one initial. Pre-computed initials like "SR" still pass through untouched, which the avatar docs rely on. The ":)" default is gone, replaced with an empty string. Co-Authored-By: Claude Opus 4.8 --- src/scripts/utilities.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/scripts/utilities.js b/src/scripts/utilities.js index af2a8f8..c60eb90 100644 --- a/src/scripts/utilities.js +++ b/src/scripts/utilities.js @@ -43,7 +43,9 @@ export function moveToFirstPosition(arr, key, value) { return arr; } -export function getInitials(name = ":)") { +// Pre-computed initials pass through untouched; a single-word name yields one +// initial, and anything longer yields first and last. +export function getInitials(name = "") { const fullName = name.trim(); if (fullName.length <= 2) { return fullName.toUpperCase(); @@ -51,7 +53,10 @@ export function getInitials(name = ":)") { const names = fullName.split(/\s+/); const firstName = names[0]; const lastName = names[names.length - 1]; - const initials = `${firstName.charAt(0)}${lastName.charAt(0)}`; + const initials = + names.length === 1 + ? firstName.charAt(0) + : `${firstName.charAt(0)}${lastName.charAt(0)}`; return initials.toUpperCase(); }