@@ -220,7 +220,7 @@ <h1>Projects</h1>
220
220
if ( xhr . readyState === DONE ) {
221
221
if ( xhr . status === OK ) {
222
222
const text = xhr . responseText ;
223
- const regexImage = / \( ( h t t p s : [ ^ \) ] + ) \) / ;
223
+ const regexImage = / \( ( h t t p [ s ] * : [ ^ \) ] + . ( g i f | j p g | j p e g | p n g | t i f | t i f f ) ) \) / i ;
224
224
const regexMattermost = / h t t p s : \/ \/ m a t t e r m o s t .b r a i n h a c k .o r g \/ b r a i n h a c k \/ c h a n n e l s \/ ( [ ^ " \) ] + ) / ;
225
225
const arrImage = text . match ( regexImage ) ;
226
226
const arrMattermost = text . match ( regexMattermost ) ;
@@ -257,49 +257,46 @@ <h1>Projects</h1>
257
257
return result ;
258
258
}
259
259
260
- function get_repo_list ( ) {
260
+ async function get_repo_list ( ) {
261
261
const defaultImages = [
262
262
"https://generative-placeholders.glitch.me/image?width=300&height=200&style=triangles" ,
263
263
"https://generative-placeholders.glitch.me/image?width=300&height=200"
264
264
]
265
- const xhr = new XMLHttpRequest ( ) ;
266
- xhr . open ( 'GET' , 'https://api.github.com/search/repositories?q=topic:brainweb fork:true' ) ;
267
- xhr . send ( null ) ;
268
- xhr . onreadystatechange = function ( ) {
269
- const DONE = 4 ;
270
- const OK = 200 ;
271
- if ( xhr . readyState === DONE ) {
272
- if ( xhr . status === OK ) {
273
- const res = JSON . parse ( xhr . responseText ) ;
274
- for ( let repo of res . items ) {
275
- ( ( aRepo ) => {
276
- const {
277
- name,
278
- description,
279
- html_url,
280
- open_issues,
281
- stargazers_count,
282
- language,
283
- homepage
284
- } = aRepo ;
285
- get_data_from_readme ( html_url ) . then ( ( res ) => {
286
- const { image, mattermost} = res ;
287
- app . projects . push ( {
288
- imgSrc :( image ) ?image :defaultImages [ parseInt ( defaultImages . length * Math . random ( ) ) ] ,
289
- projectName : name ,
290
- projectDescription : description ,
291
- projectURL : html_url ,
292
- projectInfo : { description, html_url, open_issues, stargazers_count, language, homepage} ,
293
- projectMattermost : mattermost
294
- } )
295
- } ) . catch ( ( e ) => console . log ) ;
296
- } ) ( repo ) ;
297
- }
298
- } else {
299
- console . log ( 'Error: ' + xhr . status ) ;
265
+ let response , res ;
266
+ try {
267
+ response = await fetch ( 'https://api.github.com/search/repositories?q=topic:brainweb fork:true' ) ;
268
+ res = await response . json ( ) ;
269
+ } catch ( err ) {
270
+ throw new Error ( err ) ;
271
+ }
272
+ for ( let repo of res . items ) {
273
+ ( async ( aRepo ) => {
274
+ const {
275
+ name,
276
+ description,
277
+ html_url,
278
+ open_issues,
279
+ stargazers_count,
280
+ language,
281
+ homepage
282
+ } = aRepo ;
283
+ let res ;
284
+ try {
285
+ res = await get_data_from_readme ( html_url ) ;
286
+ } catch ( err ) {
287
+ throw new Error ( err ) ;
300
288
}
301
- }
302
- } ;
289
+ const { image, mattermost} = res ;
290
+ app . projects . push ( {
291
+ imgSrc :( image ) ?image :defaultImages [ parseInt ( defaultImages . length * Math . random ( ) ) ] ,
292
+ projectName : name ,
293
+ projectDescription : description ,
294
+ projectURL : html_url ,
295
+ projectInfo : { description, html_url, open_issues, stargazers_count, language, homepage} ,
296
+ projectMattermost : mattermost
297
+ } ) ;
298
+ } ) ( repo ) ;
299
+ }
303
300
}
304
301
get_repo_list ( ) ;
305
302
0 commit comments