Skip to content

Commit d7d359c

Browse files
committed
Add contributors page
1 parent c9a5bb2 commit d7d359c

File tree

4 files changed

+105
-2
lines changed

4 files changed

+105
-2
lines changed

.github/contributors.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import sys
2+
import requests
3+
4+
try:
5+
filename = sys.argv[1]
6+
except IndexError:
7+
print("Usage: contributors.py file.md")
8+
exit(1)
9+
10+
repo_owner = "rochacbruno"
11+
repo_name = "marmite"
12+
contributors_url = (
13+
f"https://api.github.com/repos/{repo_owner}/{repo_name}/contributors"
14+
)
15+
16+
response = requests.get(contributors_url)
17+
if response.status_code != 200:
18+
raise Exception(f"Failed to fetch contributors: {response.status_code}")
19+
20+
contributors = response.json()
21+
contributors_sorted = reversed(
22+
sorted(contributors, key=lambda user: user["contributions"])
23+
)
24+
25+
with open(filename, "w") as file:
26+
file.write("# Contributors\n\n")
27+
28+
for i, contributor in enumerate(contributors_sorted):
29+
# Start a new grid after every 5 contributors
30+
if i % 5 == 0:
31+
if i != 0:
32+
file.write("</div>\n")
33+
file.write('<div class="grid" style="display: flex;">\n')
34+
35+
username = contributor["login"]
36+
profile_url = contributor["html_url"]
37+
avatar_url = contributor["avatar_url"]
38+
contributions = contributor["contributions"]
39+
40+
file.write(' <article style="width: 250px;text-align: center;">\n')
41+
file.write(
42+
' <header style="text-align: center;">'
43+
f'<a href="{profile_url}" target="_blank">'
44+
f"{username}</a></header>\n"
45+
)
46+
file.write(
47+
f' <a href="{profile_url}" target="_blank">'
48+
f'<img src="{avatar_url}" style="width: 100px;"></a>\n'
49+
)
50+
file.write(
51+
' <footer style="text-align: center;">'
52+
f"{contributions} commits</footer>\n"
53+
)
54+
file.write(" </article>\n")
55+
56+
file.write("</div>\n")
57+
58+
print("contributors.md file has been generated!")

.github/marmite.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ tagline: Simply create a static blog from markdown files
33
url: https://rochacbruno.github.io/marmite/
44
menu:
55
- ['Docs', 'tag/docs.html']
6-
- ['Create a blog', "https://github.com/rochacbruno/blog/"]
7-
- ['Github', 'https://github.com/rochacbruno/marmite/']
6+
- ['Contributors', 'contributors.html']
87
- ['Tags', 'tags.html']
8+
- ['Github', 'https://github.com/rochacbruno/marmite/']
99
extra:
1010
comments:
1111
title: Comments

.github/workflows/main.yml

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ jobs:
5757
rm marmitesite/marmite.yaml
5858
cp .github/marmite.yaml marmitesite/marmite.yaml
5959
60+
- uses: actions/setup-python@v5
61+
with:
62+
python-version: '3.12'
63+
64+
- name: Generate contributors page
65+
run: |
66+
python -m pip install requests
67+
python .github/contributors.py marmitesite/content/contributors.md
68+
6069
- name: Build site 🏗️
6170
run: marmite marmitesite site --debug
6271

example/content/contributors.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Contributors
2+
3+
<div class="grid" style="display: flex;">
4+
<article style="width: 250px;text-align: center;">
5+
<header style="text-align: center;"><a href="https://github.com/rochacbruno" target="_blank">rochacbruno</a></header>
6+
<a href="https://github.com/rochacbruno" target="_blank"><img src="https://avatars.githubusercontent.com/u/458654?v=4" style="width: 100px;"></a>
7+
<footer style="text-align: center;">63 commits</footer>
8+
</article>
9+
<article style="width: 250px;text-align: center;">
10+
<header style="text-align: center;"><a href="https://github.com/scovl" target="_blank">scovl</a></header>
11+
<a href="https://github.com/scovl" target="_blank"><img src="https://avatars.githubusercontent.com/u/1684061?v=4" style="width: 100px;"></a>
12+
<footer style="text-align: center;">6 commits</footer>
13+
</article>
14+
<article style="width: 250px;text-align: center;">
15+
<header style="text-align: center;"><a href="https://github.com/karlamagueta" target="_blank">karlamagueta</a></header>
16+
<a href="https://github.com/karlamagueta" target="_blank"><img src="https://avatars.githubusercontent.com/u/64945344?v=4" style="width: 100px;"></a>
17+
<footer style="text-align: center;">3 commits</footer>
18+
</article>
19+
<article style="width: 250px;text-align: center;">
20+
<header style="text-align: center;"><a href="https://github.com/rdenadai" target="_blank">rdenadai</a></header>
21+
<a href="https://github.com/rdenadai" target="_blank"><img src="https://avatars.githubusercontent.com/u/917516?v=4" style="width: 100px;"></a>
22+
<footer style="text-align: center;">3 commits</footer>
23+
</article>
24+
<article style="width: 250px;text-align: center;">
25+
<header style="text-align: center;"><a href="https://github.com/SkySingh04" target="_blank">SkySingh04</a></header>
26+
<a href="https://github.com/SkySingh04" target="_blank"><img src="https://avatars.githubusercontent.com/u/114267538?v=4" style="width: 100px;"></a>
27+
<footer style="text-align: center;">1 commits</footer>
28+
</article>
29+
</div>
30+
<div class="grid" style="display: flex;">
31+
<article style="width: 250px;text-align: center;">
32+
<header style="text-align: center;"><a href="https://github.com/zokaibr" target="_blank">zokaibr</a></header>
33+
<a href="https://github.com/zokaibr" target="_blank"><img src="https://avatars.githubusercontent.com/u/8548385?v=4" style="width: 100px;"></a>
34+
<footer style="text-align: center;">1 commits</footer>
35+
</article>
36+
</div>

0 commit comments

Comments
 (0)