Update website
This commit is contained in:
parent
8f81dc01bd
commit
560432ad3b
@ -113,6 +113,48 @@ function expandJournalReferences($text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function convertFirstNameToInitial($name) {
|
||||||
|
// Trim any whitespace
|
||||||
|
$name = trim($name);
|
||||||
|
|
||||||
|
// Return empty string if name is empty
|
||||||
|
if (empty($name)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split the name into parts
|
||||||
|
$parts = preg_split('/\s+/', $name);
|
||||||
|
|
||||||
|
// Process each part
|
||||||
|
$result = array_map(function($part) {
|
||||||
|
// Skip if part is empty
|
||||||
|
if (empty($part)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's already an initial (single character followed by optional period)
|
||||||
|
if (preg_match('/^[A-Z]\.?$/', $part)) {
|
||||||
|
// Ensure it has a period
|
||||||
|
return rtrim($part, '.') . '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's a hyphenated name, handle each part
|
||||||
|
if (strpos($part, '-') !== false) {
|
||||||
|
$hyphenParts = explode('-', $part);
|
||||||
|
$initials = array_map(function($p) {
|
||||||
|
return ucfirst($p[0]) . '.';
|
||||||
|
}, $hyphenParts);
|
||||||
|
return implode('-', $initials);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regular name: take first character, capitalize it, add period
|
||||||
|
return ucfirst($part[0]) . '.';
|
||||||
|
}, $parts);
|
||||||
|
|
||||||
|
// Join the parts back together
|
||||||
|
return implode(' ', array_filter($result));
|
||||||
|
}
|
||||||
|
|
||||||
$m = setup_mustache();
|
$m = setup_mustache();
|
||||||
|
|
||||||
|
|
||||||
@ -124,6 +166,7 @@ $listener->addProcessor(new NamesProcessor());
|
|||||||
$listener->addProcessor(static function (array $entry) {
|
$listener->addProcessor(static function (array $entry) {
|
||||||
$entry['title'] = removeBoundingBraces($entry['title']);
|
$entry['title'] = removeBoundingBraces($entry['title']);
|
||||||
foreach ($entry['author'] as $i=>$v) {
|
foreach ($entry['author'] as $i=>$v) {
|
||||||
|
$entry['author'][$i]['first'] = convertFirstNameToInitial($v['first']);
|
||||||
$entry['author'][$i]['last'] = removeBoundingBraces($v['last']);
|
$entry['author'][$i]['last'] = removeBoundingBraces($v['last']);
|
||||||
}
|
}
|
||||||
if (isset($entry['journal'])) {
|
if (isset($entry['journal'])) {
|
||||||
|
Loading…
Reference in New Issue
Block a user