File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,25 @@ data.stars = github.stargazers_count;
4747data . followers . mastodon = mastodon . followers_count ;
4848data . followers . bluesky = bluesky . followersCount ;
4949
50+ // Fetch the latest Astro Twitter followers count from the Twitter API.
51+ // Conditional because it’s the one API that needs authorization.
52+ if ( process . env . TWITTER_BEARER_TOKEN ) {
53+ const twitter = z
54+ . object ( {
55+ data : z . object ( {
56+ public_metrics : z . object ( { followers_count : z . number ( ) } ) ,
57+ } ) ,
58+ } )
59+ . parse (
60+ await fetch (
61+ 'https://api.x.com/2/users/by/username/astrodotbuild?user.fields=public_metrics' ,
62+ { headers : { Authorization : `Bearer ${ process . env . TWITTER_BEARER_TOKEN } ` } } ,
63+ ) . then ( ( res ) => res . json ( ) ) ,
64+ ) ;
65+ console . log ( `✔︎ Twitter followers: ${ twitter . data . public_metrics . followers_count } ` ) ;
66+ data . followers . twitter = twitter . data . public_metrics . followers_count ;
67+ }
68+
5069// Write updated stats back to src/data/stats.json.
5170console . log ( '‣ Writing updated stats to src/data/stats.json...' ) ;
5271await writeFile ( 'src/data/stats.json' , JSON . stringify ( data , null , '\t' ) ) ;
You can’t perform that action at this time.
0 commit comments