Skip to content

Commit b7fd06d

Browse files
committed
better image parsing
1 parent 56f4953 commit b7fd06d

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

projects/index.html

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ <h1>Projects</h1>
220220
if (xhr.readyState === DONE) {
221221
if (xhr.status === OK) {
222222
const text = xhr.responseText;
223-
const regexImage = /\((https:[^\) ]+)\)/;
223+
const regexImage = /\((http[s]*:[^\) ]+.(gif|jpg|jpeg|png|tif|tiff))\)/i;
224224
const regexMattermost = /https:\/\/mattermost.brainhack.org\/brainhack\/channels\/([^"\)]+)/;
225225
const arrImage = text.match(regexImage);
226226
const arrMattermost = text.match(regexMattermost);
@@ -257,49 +257,46 @@ <h1>Projects</h1>
257257
return result;
258258
}
259259

260-
function get_repo_list() {
260+
async function get_repo_list() {
261261
const defaultImages = [
262262
"https://generative-placeholders.glitch.me/image?width=300&height=200&style=triangles",
263263
"https://generative-placeholders.glitch.me/image?width=300&height=200"
264264
]
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);
300288
}
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+
}
303300
}
304301
get_repo_list();
305302

0 commit comments

Comments
 (0)