Skip to content

Commit

Permalink
Add contributors page
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Oct 24, 2024
1 parent c9a5bb2 commit 1fc0518
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
58 changes: 58 additions & 0 deletions .github/contributors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import sys
import requests

try:
filename = sys.argv[1]
except IndexError:
print("Usage: contributors.py file.md")
exit(1)

repo_owner = "rochacbruno"
repo_name = "marmite"
contributors_url = (
f"https://api.github.com/repos/{repo_owner}/{repo_name}/contributors"
)

response = requests.get(contributors_url)
if response.status_code != 200:
raise Exception(f"Failed to fetch contributors: {response.status_code}")

contributors = response.json()
contributors_sorted = reversed(
sorted(contributors, key=lambda user: user["contributions"])
)

with open(filename, "w") as file:
file.write("# Contributors\n\n")

for i, contributor in enumerate(contributors_sorted):
# Start a new grid after every 5 contributors
if i % 5 == 0:
if i != 0:
file.write("</div>\n")
file.write('<div class="grid" style="display: flex;">\n')

username = contributor["login"]
profile_url = contributor["html_url"]
avatar_url = contributor["avatar_url"]
contributions = contributor["contributions"]

file.write(' <article style="width: 250px;text-align: center;">\n')
file.write(
' <header style="text-align: center;">'
f'<a href="{profile_url}" target="_blank">'
f"{username}</a></header>\n"
)
file.write(
f' <a href="{profile_url}" target="_blank">'
f'<img src="{avatar_url}" style="width: 100px;"></a>\n'
)
file.write(
' <footer style="text-align: center;">'
f"{contributions} commits</footer>\n"
)
file.write(" </article>\n")

file.write("</div>\n")

print("contributors.md file has been generated!")
4 changes: 2 additions & 2 deletions .github/marmite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ tagline: Simply create a static blog from markdown files
url: https://rochacbruno.github.io/marmite/
menu:
- ['Docs', 'tag/docs.html']
- ['Create a blog', "https://github.com/rochacbruno/blog/"]
- ['Github', 'https://github.com/rochacbruno/marmite/']
- ['Contributors', 'contributors.html']
- ['Tags', 'tags.html']
- ['Github', 'https://github.com/rochacbruno/marmite/']
extra:
comments:
title: Comments
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ jobs:
rm marmitesite/marmite.yaml
cp .github/marmite.yaml marmitesite/marmite.yaml
- name: Generate contributors page
uses: actions/setup-python@v5
with:
python-version: '3.12'
run: |
python -m pip install requests
python .github/contributors.py marmitesite/content/contributors.md
- name: Build site 🏗️
run: marmite marmitesite site --debug

Expand Down
36 changes: 36 additions & 0 deletions example/content/contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Contributors

<div class="grid" style="display: flex;">
<article style="width: 250px;text-align: center;">
<header style="text-align: center;"><a href="https://github.com/rochacbruno" target="_blank">rochacbruno</a></header>
<a href="https://github.com/rochacbruno" target="_blank"><img src="https://avatars.githubusercontent.com/u/458654?v=4" style="width: 100px;"></a>
<footer style="text-align: center;">63 commits</footer>
</article>
<article style="width: 250px;text-align: center;">
<header style="text-align: center;"><a href="https://github.com/scovl" target="_blank">scovl</a></header>
<a href="https://github.com/scovl" target="_blank"><img src="https://avatars.githubusercontent.com/u/1684061?v=4" style="width: 100px;"></a>
<footer style="text-align: center;">6 commits</footer>
</article>
<article style="width: 250px;text-align: center;">
<header style="text-align: center;"><a href="https://github.com/karlamagueta" target="_blank">karlamagueta</a></header>
<a href="https://github.com/karlamagueta" target="_blank"><img src="https://avatars.githubusercontent.com/u/64945344?v=4" style="width: 100px;"></a>
<footer style="text-align: center;">3 commits</footer>
</article>
<article style="width: 250px;text-align: center;">
<header style="text-align: center;"><a href="https://github.com/rdenadai" target="_blank">rdenadai</a></header>
<a href="https://github.com/rdenadai" target="_blank"><img src="https://avatars.githubusercontent.com/u/917516?v=4" style="width: 100px;"></a>
<footer style="text-align: center;">3 commits</footer>
</article>
<article style="width: 250px;text-align: center;">
<header style="text-align: center;"><a href="https://github.com/SkySingh04" target="_blank">SkySingh04</a></header>
<a href="https://github.com/SkySingh04" target="_blank"><img src="https://avatars.githubusercontent.com/u/114267538?v=4" style="width: 100px;"></a>
<footer style="text-align: center;">1 commits</footer>
</article>
</div>
<div class="grid" style="display: flex;">
<article style="width: 250px;text-align: center;">
<header style="text-align: center;"><a href="https://github.com/zokaibr" target="_blank">zokaibr</a></header>
<a href="https://github.com/zokaibr" target="_blank"><img src="https://avatars.githubusercontent.com/u/8548385?v=4" style="width: 100px;"></a>
<footer style="text-align: center;">1 commits</footer>
</article>
</div>

0 comments on commit 1fc0518

Please sign in to comment.