@@ -9,7 +9,7 @@ type Result = {
9
9
repo : string
10
10
stars : number
11
11
pkg : string
12
- img : string
12
+ avatarID : string
13
13
}
14
14
15
15
export async function crawlDependents ( ) {
@@ -51,7 +51,8 @@ async function crawlDependentsPage(url: string) {
51
51
const $ = cheerio . load ( html )
52
52
const results : Result [ ] = [ ]
53
53
$ ( '[data-test-id="dg-repo-pkg-dependent"]' ) . each ( ( index , element ) => {
54
- const img = $ ( element ) . find ( 'img' ) . attr ( 'src' ) ?. replace ( 's=40' , 's=64' )
54
+ const img = $ ( element ) . find ( 'img' ) . attr ( 'src' ) // ?.replace('s=40', 's=64')
55
+ const avatarID = getAvatarID ( img ?? '' )
55
56
const repoLink = $ ( element ) . find ( 'a[data-hovercard-type="repository"]' )
56
57
const starsStr = $ ( element )
57
58
. find ( 'a[data-hovercard-type="repository"]' )
@@ -65,15 +66,28 @@ async function crawlDependentsPage(url: string) {
65
66
. text ( )
66
67
. trim ( )
67
68
const stars = parseInt ( starsStr . replace ( / , / g, '' ) , 10 )
68
- if ( ! isNaN ( stars ) && repoLink . length > 0 && ownerStr . length > 0 && img ) {
69
+ if (
70
+ ! isNaN ( stars ) &&
71
+ repoLink . length > 0 &&
72
+ ownerStr . length > 0 &&
73
+ avatarID
74
+ ) {
69
75
const repoName = repoLink . text ( )
70
76
const repo = `${ ownerStr } /${ repoName } `
71
77
if ( ! [ 'franky47' , '47ng' ] . includes ( ownerStr ) ) {
72
- results . push ( { repo, stars, pkg, img } )
78
+ results . push ( { repo, stars, pkg, avatarID } )
73
79
}
74
80
}
75
81
} )
76
82
const nextButton = $ ( 'div.paginate-container a:contains(Next)' )
77
83
const nextPage = nextButton ?. attr ( 'href' ) ?? null
78
84
return { results, nextPage }
79
85
}
86
+
87
+ const gitHubAvatarURLRegExp =
88
+ / ^ h t t p s : \/ \/ a v a t a r s \. g i t h u b u s e r c o n t e n t \. c o m \/ u \/ ( \d + ) \? /
89
+
90
+ function getAvatarID ( src : string ) {
91
+ const match = src . match ( gitHubAvatarURLRegExp )
92
+ return match ? match [ 1 ] : undefined
93
+ }
0 commit comments