@@ -4,25 +4,40 @@ import classes from './avatar-stack.module.css';
44type AvatarStackProps = {
55 authors : string ;
66} ;
7- const avatars = [
8- 'ardoq' ,
9- 'avinor' ,
10- 'brønnøysundregistrene' ,
11- 'digdir' ,
12- 'designsystemet' ,
13- 'ksdigital' ,
14- 'ks' ,
15- 'mattilsynet' ,
16- 'nav' ,
17- 'oslokommune' ,
18- 'skatteetaten' ,
19- ] ;
7+
8+ const avatarMap = {
9+ ardoq : 'ardoq.svg' ,
10+ avinor : 'avinor.svg' ,
11+ brønnøysundregistrene : 'brønnøysundregistrene.svg' ,
12+ digdir : 'digdir.svg' ,
13+ designsystemet : 'designsystemet.svg' ,
14+ 'ks digital' : 'ksdigital.svg' ,
15+ ks : 'ks.png' ,
16+ mattilsynet : 'mattilsynet.svg' ,
17+ nav : 'nav.svg' ,
18+ 'oslo kommune' : 'oslokommune.svg' ,
19+ skatteetaten : 'skatteetaten.svg' ,
20+ } as const ;
21+
22+ type AvatarKey = keyof typeof avatarMap ;
2023
2124export const AvatarStack = ( { authors } : AvatarStackProps ) => {
2225 const authorsLowercase = authors . toLowerCase ( ) ;
23- const matchedAvatars = avatars . filter ( ( avatar ) =>
24- authorsLowercase . includes ( avatar ) ,
26+
27+ // Split authors string on common delimiters
28+ const authorWords = authorsLowercase . split ( / [ \s , / - ] + / ) . filter ( Boolean ) ;
29+
30+ const matchedAvatars = ( Object . keys ( avatarMap ) as AvatarKey [ ] ) . filter (
31+ ( key ) => {
32+ // Split key on delimiters
33+ const keyWords = key . split ( / [ \s - ] + / ) . filter ( Boolean ) ;
34+ // Check if all words in the key match words in the authors string
35+ return keyWords . every ( ( word ) =>
36+ authorWords . some ( ( authorWord ) => authorWord . includes ( word ) ) ,
37+ ) ;
38+ } ,
2539 ) ;
40+
2641 if ( matchedAvatars . length === 0 ) {
2742 return null ;
2843 }
@@ -33,8 +48,12 @@ export const AvatarStack = ({ authors }: AvatarStackProps) => {
3348 style = { { '--n' : matchedAvatars . length } as CSSProperties }
3449 aria-hidden
3550 >
36- { matchedAvatars . map ( ( avatar ) => (
37- < img key = { avatar } src = { `/img/avatars/${ avatar } .svg` } alt = '' />
51+ { matchedAvatars . map ( ( avatarKey ) => (
52+ < img
53+ key = { avatarKey }
54+ src = { `/img/avatars/${ avatarMap [ avatarKey ] } ` }
55+ alt = ''
56+ />
3857 ) ) }
3958 </ span >
4059 ) ;
0 commit comments