From 5c5085fe9206af4e2e3c46c86330010196d30446 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 15 Jan 2026 16:15:13 -0500 Subject: [PATCH 1/2] style(Authors): format as "First Last" Address #179 Updated the Authors.astro component with: Added capitalizeNamePart() helper - Ensures proper capitalization (first letter uppercase, rest lowercase) Added formatAuthorName() helper - Intelligently converts "Last, First" format to "First Last": - Detects the comma separator - Splits on comma - Reverses the order - Applies proper capitalization to each part - Falls back to simple capitalization for non-comma names - Updated getAuthorName() function - Now uses the new formatting logic for all name types: - Structured name objects (given/family) - String names - Literal name objects --- src/components/Authors.astro | 54 +++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/src/components/Authors.astro b/src/components/Authors.astro index 7237c80f..f01abc20 100644 --- a/src/components/Authors.astro +++ b/src/components/Authors.astro @@ -18,21 +18,61 @@ interface Props { const { authors, affiliations } = Astro.props; -// Helper function to get author name as string +// Helper function to capitalize the first letter of a name part +function capitalizeNamePart(namePart: string): string { + if (!namePart || namePart.length === 0) return namePart; + return namePart.charAt(0).toUpperCase() + namePart.slice(1).toLowerCase(); +} + +// Helper function to format and capitalize an author name +// Handles "Last, First" format by converting to "First Last" +function formatAuthorName(name: string): string { + if (!name || name.length === 0) return name; + + // Check if name is in "Last, First" format (contains comma) + if (name.includes(',')) { + const parts = name.split(',').map(p => p.trim()); + if (parts.length === 2) { + // Reverse to "First Last" format + const firstName = parts[1]; + const lastName = parts[0]; + const formattedFirst = firstName + .split(/\s+/) + .map(p => capitalizeNamePart(p)) + .join(' '); + const formattedLast = lastName + .split(/\s+/) + .map(p => capitalizeNamePart(p)) + .join(' '); + return `${formattedFirst} ${formattedLast}`; + } + } + + // Otherwise, just capitalize each word part + return name + .split(/\s+/) + .map(part => capitalizeNamePart(part)) + .join(' '); +} + +// Helper function to get author name as string with proper formatting and capitalization function getAuthorName(author: Contributor): string { if (!author.name) return 'Unknown Author'; if (typeof author.name === 'object' && typeof author.name.given === 'string' && typeof author.name.family === 'string') { const parts: string[] = []; - if (author.name.given) parts.push(author.name.given); - if (author.name.family) parts.push(author.name.family); + // Capitalize each name part properly + if (author.name.given) parts.push(capitalizeNamePart(author.name.given)); + if (author.name.family) parts.push(capitalizeNamePart(author.name.family)); if (parts.length > 0) return parts.join(' '); } - // If name is a string, return it directly - if (typeof author.name === 'string') return author.name; - // If name is an object, use the literal property + // If name is a string, format and capitalize it + if (typeof author.name === 'string') { + return formatAuthorName(author.name); + } + // If name is an object, use the literal property and format if (typeof author.name === 'object' && author.name.literal) { - return author.name.literal; + return formatAuthorName(author.name.literal); } return 'Unknown Author'; } From 8f46829415fee97fd2808ade04d623790836e7e3 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 16 Jan 2026 16:23:31 -0500 Subject: [PATCH 2/2] style(Authors): less aggressive capitalization The capitalizeNamePart() function unconditionally lowercases all characters after the first letter, which could incorrectly format names with special capitalization patterns such as 'McDonald', 'O'Brien', 'van der Waals', or 'McPherson'. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/components/Authors.astro | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Authors.astro b/src/components/Authors.astro index f01abc20..c388b574 100644 --- a/src/components/Authors.astro +++ b/src/components/Authors.astro @@ -21,7 +21,16 @@ const { authors, affiliations } = Astro.props; // Helper function to capitalize the first letter of a name part function capitalizeNamePart(namePart: string): string { if (!namePart || namePart.length === 0) return namePart; - return namePart.charAt(0).toUpperCase() + namePart.slice(1).toLowerCase(); + + // If the part is all lower or all upper, normalize to "Titlecase" + const isAllLower = namePart === namePart.toLowerCase(); + const isAllUpper = namePart === namePart.toUpperCase(); + if (isAllLower || isAllUpper) { + return namePart.charAt(0).toUpperCase() + namePart.slice(1).toLowerCase(); + } + + // Otherwise, assume the existing capitalization is intentional + return namePart; } // Helper function to format and capitalize an author name