@@ -8,7 +8,7 @@ import { type NpmUser } from '~/types';
88import tw from '~/util/tailwind' ;
99
1010type Props = {
11- author ?: NpmUser ;
11+ author ?: NpmUser | string ;
1212 compact ?: boolean ;
1313} ;
1414
@@ -25,13 +25,37 @@ export default function PackageAuthor({ author, compact }: Props) {
2525 ) ;
2626 }
2727
28+ if ( typeof author === 'string' ) {
29+ if ( author . includes ( 'github.com/' ) ) {
30+ const ghUsername = extractGitHubUsername ( author ) ;
31+
32+ return (
33+ < View >
34+ < A href = { `https://github.com/${ ghUsername } ` } style = { authorContainerStyle } >
35+ < UserAvatar src = { `https://github.com/${ ghUsername } .png` } alt = { `${ ghUsername } avatar` } />
36+ < View >
37+ < Caption style = { labelStyle } > { ghUsername } </ Caption >
38+ < span style = { sublabelStyle } >
39+ { author . replace ( / \s * \( ? h t t p s ? : \/ \/ \S + \) ? \s * / g, '' ) . trim ( ) }
40+ </ span >
41+ </ View >
42+ </ A >
43+ </ View >
44+ ) ;
45+ }
46+ return (
47+ < View >
48+ < Label > { author } </ Label >
49+ </ View >
50+ ) ;
51+ }
52+
2853 const potentialHref = author . url ?? author . email ;
2954
3055 // URL
3156 if ( potentialHref && ! potentialHref . includes ( '@' ) ) {
3257 if ( potentialHref . includes ( 'github.com/' ) ) {
33- const [ , potentialGHUsername ] = potentialHref . split ( 'github.com/' ) ;
34- const ghUsername = potentialGHUsername . replace ( / [ < > ( ) ] / g, '' ) ;
58+ const ghUsername = extractGitHubUsername ( potentialHref ) ;
3559 const validName = getValidName ( author . name ) ;
3660
3761 return (
@@ -107,3 +131,8 @@ function getValidName(potentialName: string): string {
107131 . join ( ' ' ) ;
108132 return cleanName . length ? cleanName : potentialName . replace ( / [ < > ( ) ] / g, '' ) ;
109133}
134+
135+ function extractGitHubUsername ( author : string ) : string | null {
136+ const [ , potentialGHUsername ] = author . split ( 'github.com/' ) ;
137+ return potentialGHUsername ? potentialGHUsername . replace ( / [ < > ( ) ] / g, '' ) : null ;
138+ }
0 commit comments