Skip to content

Commit f669512

Browse files
authored
Merge pull request #22 from dipamsen/projects-overhaul
Projects Page Overhaul
2 parents 57a667e + 064f10e commit f669512

File tree

7 files changed

+190
-206
lines changed

7 files changed

+190
-206
lines changed

get_repos.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,50 @@
33

44
ORG_NAME = 'metakgp'
55

6-
BLACKLISTED_LANGUAGES = {"Dockerfile", None, "Ruby", "CoffeeScript"}
76

87
def get_repositories(org_name):
98
url = f'https://api.github.com/orgs/{org_name}/repos'
10-
11-
repos = []
12-
13-
response = requests.get(url, params={'sort':'updated', 'per_page': 100, 'type': 'public'}) # we only have like 70 repos so don't need to handle pagination yet
14-
9+
10+
repos = dict()
11+
12+
response = requests.get(url, params={'sort': 'updated', 'per_page': 100, 'type': 'public'})
13+
1514
if response.status_code != 200:
1615
print(f"Error fetching repositories: {response.status_code} - {response.text}")
1716
return repos
18-
17+
1918
data = response.json()
20-
19+
2120
for repo in data:
22-
if repo['archived'] == False and repo['language'] not in BLACKLISTED_LANGUAGES:
23-
repos.append({
24-
'name': repo['name'],
25-
'description': repo['description'],
26-
'stars': repo['stargazers_count'],
27-
'forks': repo['forks_count'],
28-
'language': repo['language'],
29-
'homepage': repo['homepage']
30-
})
31-
21+
repos[repo.get('name')] = {
22+
'stars': repo.get('stargazers_count', 0),
23+
'forks': repo.get('forks_count', 0),
24+
}
25+
3226
return repos
3327

34-
def save_to_json(data, filename):
35-
with open(filename, 'w') as json_file:
36-
json.dump(data, json_file, indent=4)
37-
print(f"Data saved to {filename}")
28+
29+
def update_repo_data(fetched_repos, filename):
30+
with open(filename, 'r') as f:
31+
existing = json.load(f)
32+
33+
updated = []
34+
35+
for repo in existing:
36+
name = repo.get('name')
37+
fetched = fetched_repos.get(name)
38+
if fetched:
39+
repo['stars'] = fetched.get('stars', 0)
40+
repo['forks'] = fetched.get('forks', 0)
41+
42+
updated.append(repo)
43+
44+
with open(filename, 'w') as f:
45+
json.dump(updated, f, indent=4)
46+
print(f"Wrote updated data to {filename}")
47+
3848

3949
if __name__ == '__main__':
4050
repositories = get_repositories(ORG_NAME)
41-
save_to_json(repositories, "src/data/repo_data.json")
51+
update_repo_data(repositories, "src/data/repo_data.json")
4252

src/components/GithubCard.tsx

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,62 @@ import { Link } from "react-router-dom";
55

66
const RepoCard = ({ repoData }: { repoData: REPO_DATA_TYPE }) => {
77
const repo_link = `https://github.com/metakgp/${repoData.name}`;
8-
const stargazers_link = `https://github.com/metakgp/${repoData.name}/stargazers`
9-
const forks_link = `https://github.com/metakgp/${repoData.name}/forks`
8+
9+
const Surround = repoData.homepage ? ({ children }: { children: React.ReactNode }) => (
10+
<a href={repoData.homepage} target="_blank" rel="noreferrer" className="gh-card-container">
11+
{children}
12+
</a>
13+
) : ({ children }: { children: React.ReactNode }) => (
14+
<div className="gh-card-container">
15+
{children}
16+
</div>
17+
);
1018

1119
return (
12-
<Link to={repo_link} className="gh-card-container">
20+
<Surround>
1321
<div className="gh-card-header">
14-
<span className="book-icon">
15-
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" className="octicon octicon-repo mr-1 color-fg-muted">
22+
<span className="icon">
23+
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" className="octicon">
1624
<path d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path>
1725
</svg>
1826
</span>
19-
<Link to={repo_link}>
27+
<a href={repoData.homepage ? repoData.homepage : repo_link} target="_blank" rel="noreferrer">
2028
<span className="gh-repo-name">{repoData.name}</span>
21-
</Link>
29+
</a>
30+
<a href={repo_link} target="_blank" rel="noreferrer">
31+
<span className="icon">
32+
<svg width="25" height="25" viewBox="0 0 30 30" className="octicon" >
33+
<path d="M15,3C8.373,3,3,8.373,3,15c0,5.623,3.872,10.328,9.092,11.63C12.036,26.468,12,26.28,12,26.047v-2.051 c-0.487,0-1.303,0-1.508,0c-0.821,0-1.551-0.353-1.905-1.009c-0.393-0.729-0.461-1.844-1.435-2.526 c-0.289-0.227-0.069-0.486,0.264-0.451c0.615,0.174,1.125,0.596,1.605,1.222c0.478,0.627,0.703,0.769,1.596,0.769 c0.433,0,1.081-0.025,1.691-0.121c0.328-0.833,0.895-1.6,1.588-1.962c-3.996-0.411-5.903-2.399-5.903-5.098 c0-1.162,0.495-2.286,1.336-3.233C9.053,10.647,8.706,8.73,9.435,8c1.798,0,2.885,1.166,3.146,1.481C13.477,9.174,14.461,9,15.495,9 c1.036,0,2.024,0.174,2.922,0.483C18.675,9.17,19.763,8,21.565,8c0.732,0.731,0.381,2.656,0.102,3.594 c0.836,0.945,1.328,2.066,1.328,3.226c0,2.697-1.904,4.684-5.894,5.097C18.199,20.49,19,22.1,19,23.313v2.734 c0,0.104-0.023,0.179-0.035,0.268C23.641,24.676,27,20.236,27,15C27,8.373,21.627,3,15,3z"></path>
34+
</svg>
35+
</span>
36+
</a>
2237
</div>
2338
<div className="gh-card-body">
2439
{repoData.description}
2540
</div>
2641
<div className="gh-card-footer">
27-
<div className="gh-card-language-container">
28-
<span className="gh-card-circle"></span>
29-
<span className="gh-card-language">{repoData.language}</span>
42+
{repoData.language.map(lang => <div className="gh-card-language-container">
43+
<span className={`gh-card-circle gh-card-lang-${lang.toLowerCase()}`}></span>
44+
<span className="gh-card-language">{lang}</span>
45+
</div>)}
46+
<div className="gh-card-star-container">
47+
<span className="gh-card-star-icon">
48+
<svg aria-label="stars" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" className="octicon octicon-star">
49+
<path d="M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Zm0 2.445L6.615 5.5a.75.75 0 0 1-.564.41l-3.097.45 2.24 2.184a.75.75 0 0 1 .216.664l-.528 3.084 2.769-1.456a.75.75 0 0 1 .698 0l2.77 1.456-.53-3.084a.75.75 0 0 1 .216-.664l2.24-2.183-3.096-.45a.75.75 0 0 1-.564-.41L8 2.694Z"></path>
50+
</svg>
51+
</span>
52+
{repoData.stars}
53+
</div>
54+
<div className="gh-card-forks-container">
55+
<span className="gh-card-fork-icon">
56+
<svg aria-label="forks" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" className="octicon octicon-repo-forked">
57+
<path d="M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"></path>
58+
</svg>
59+
</span>
60+
{repoData.forks}
3061
</div>
31-
<Link to={stargazers_link}>
32-
<div className="gh-card-star-container">
33-
<span className="gh-card-star-icon">
34-
<svg aria-label="stars" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" className="octicon octicon-star">
35-
<path d="M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Zm0 2.445L6.615 5.5a.75.75 0 0 1-.564.41l-3.097.45 2.24 2.184a.75.75 0 0 1 .216.664l-.528 3.084 2.769-1.456a.75.75 0 0 1 .698 0l2.77 1.456-.53-3.084a.75.75 0 0 1 .216-.664l2.24-2.183-3.096-.45a.75.75 0 0 1-.564-.41L8 2.694Z"></path>
36-
</svg>
37-
</span>
38-
{repoData.stars}
39-
</div>
40-
</Link>
41-
<Link to={forks_link}>
42-
<div className="gh-card-forks-container">
43-
<span className="gh-card-fork-icon">
44-
<svg aria-label="forks" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" className="octicon octicon-repo-forked">
45-
<path d="M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"></path>
46-
</svg>
47-
</span>
48-
{repoData.forks}
49-
</div>
50-
</Link>
5162
</div>
52-
</Link>
63+
</Surround>
5364
)
5465
}
5566

0 commit comments

Comments
 (0)