11export { Badges } from './badges' ;
22export interface Author {
33 name : string ;
4- affiliation : string ;
4+ affiliation : string [ ] ;
55}
66
77
88export function AuthorList ( { authors } : { authors : Author [ ] } ) {
9- let uniqueAffiliations = authors . map ( author => author . affiliation ) . filter ( ( value , index , self ) => self . indexOf ( value ) === index ) ;
9+ // Flatten the affiliations and get unique ones
10+ let uniqueAffiliations = Array . from ( new Set ( authors . flatMap ( author => author . affiliation ) ) ) ;
1011 const affiliationIndices = uniqueAffiliations . reduce ( ( acc , affiliation , index ) => {
1112 acc [ affiliation ] = index + 1 ; // Start indexing from 1 for superscripts
1213 return acc ;
1314 } , { } as { [ key : string ] : number } ) ;
14- return (
15- < div className = "pb-0" >
16- < div className = "text-center text-xl" >
17- { authors . map ( ( author , index ) => (
18- < span key = { index } >
19- { author . name } < sup > { affiliationIndices [ author . affiliation ] } </ sup >
20- { index < authors . length - 1 ? ', ' : '' }
21- </ span >
22- ) ) }
23- </ div >
24-
25- { /* Display affiliation list */ }
26- < div className = "text-center text-lg" >
27- { uniqueAffiliations . map ( ( affiliation , index ) => (
28- < span key = { index } >
29- < sup > { index + 1 } </ sup > { affiliation }
30- { index < uniqueAffiliations . length - 1 ? ', ' : '' }
31- </ span >
32- ) ) }
33- </ div >
34- </ div >
35- ) ;
15+
16+ return (
17+ < div className = "pb-0" >
18+ < div className = "text-center text-xl" >
19+ { authors . map ( ( author , index ) => (
20+ < span key = { index } >
21+ { author . name }
22+ { author . affiliation . map ( ( aff , i ) => (
23+ < sup key = { i } > { affiliationIndices [ aff ] } </ sup >
24+ ) ) }
25+ { index < authors . length - 1 ? ', ' : '' }
26+ </ span >
27+ ) ) }
28+ </ div >
29+
30+ { /* Display affiliation list */ }
31+ < div className = "text-center text-lg" >
32+ { uniqueAffiliations . map ( ( affiliation , index ) => (
33+ < span key = { index } >
34+ < sup > { index + 1 } </ sup > { affiliation }
35+ { index < uniqueAffiliations . length - 1 ? ', ' : '' }
36+ </ span >
37+ ) ) }
38+ </ div >
39+ </ div >
40+ ) ;
3641}
3742
3843
3944export function Authors ( { authors } : { authors : string } ) {
40- // authors in the format: author1, affliation1; author2, affiliation2; ...
41- const authorList = authors . split ( ';' ) . map ( author => {
42- const [ name , affiliation ] = author . split ( ',' ) ;
43- return { name : name . trim ( ) , affiliation : affiliation . trim ( ) } ;
45+ // authors in the format: author1, affiliation1; affiliation2; author2, affiliation3; ...
46+ const authorList : Author [ ] = [ ] ;
47+ let currentAuthor : Author | null = null ;
48+
49+ authors . split ( ';' ) . forEach ( part => {
50+ const [ name , affiliation ] = part . split ( ',' ) ;
51+
52+ if ( affiliation !== undefined ) {
53+ // New author with affiliation
54+ if ( currentAuthor ) {
55+ authorList . push ( currentAuthor ) ;
56+ }
57+ currentAuthor = { name : name . trim ( ) , affiliation : [ affiliation . trim ( ) ] } ;
58+ } else {
59+ if ( ! currentAuthor ) {
60+ throw new Error ( `Invalid author string: ${ authors } ` ) ;
61+ }
62+ // Additional affiliation for the current author
63+ currentAuthor . affiliation . push ( part . trim ( ) ) ;
64+ }
4465 } ) ;
66+
67+ if ( currentAuthor ) {
68+ authorList . push ( currentAuthor ) ;
69+ }
70+
4571 return < AuthorList authors = { authorList } /> ;
4672}
0 commit comments