Skip to content

Commit 47ea1ff

Browse files
committed
feat: Add other type of img file in banner - .svg
1 parent 944c2a7 commit 47ea1ff

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

.DS_Store

8 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-automated-repos",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"description": "Github-automated-repos is the lib that gives you the power to manage the view of your projects on your website in one place!",
55
"main": "index.js",
66
"scripts": {

src/.DS_Store

6 KB
Binary file not shown.

src/hooks/useGithubAutomatedRepos.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface IGithubRepos {
2525
description: string;
2626
id: number;
2727
homepage: string;
28+
banner: () => string;
2829
}
2930

3031
/**
@@ -34,6 +35,7 @@ export interface IGithubRepos {
3435
*/
3536
export function useGitHubAutomatedRepos(usernameGitHub: string, keyWordDeploy: string) {
3637
const [repository, setRepository] = useState<IGithubRepos[]>([]);
38+
3739
useEffect(() => {
3840
fetch(`https://api.github.com/users/${usernameGitHub}/repos?sort=created&per_page=999`)
3941
.then((response) => response.json())
@@ -44,14 +46,30 @@ export function useGitHubAutomatedRepos(usernameGitHub: string, keyWordDeploy: s
4446

4547
dataFilter = repository.filter((item: IGithubRepos) => item.topics.includes(keyWordDeploy as never));
4648

49+
const typeImg = ['svg', 'png'];
50+
function checkImage(usernameGitHub: string, repositoryName: string): string {
51+
let checkURL = '';
52+
typeImg.map((type)=> {
53+
const url = `https://raw.githubusercontent.com/${usernameGitHub}/${repositoryName}/main/src/assets/imgs/banner.${type}`;
54+
const http = new XMLHttpRequest();
55+
http.open('HEAD', url, false);
56+
http.send();
57+
58+
if (http.status === 200) {
59+
checkURL = url;
60+
}
61+
});
62+
return checkURL;
63+
}
64+
4765
return dataFilter.map((item: IGithubRepos) => ({
4866
id: item.id,
4967
name: item.name,
5068
html_url: item.html_url,
5169
description: item.description,
5270
topics: item.topics,
5371
homepage: item.homepage,
54-
banner: `https://raw.githubusercontent.com/${usernameGitHub}/${item.name}/main/src/assets/imgs/banner.png`,
72+
banner: checkImage(usernameGitHub, item.name),
5573
}));
5674
}
5775

0 commit comments

Comments
 (0)