From a534b39bb7b05a30ae758453209b49adce2414ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Wed, 13 Mar 2024 14:09:39 +0100 Subject: [PATCH] refactor: Update premium sponsors display --- .../index.md.jinja | 17 ++------ ...if insiders %}insiders.js{% endif %}.jinja | 39 +++++++++++-------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/project/docs/{% if insiders %}insiders{% endif %}/index.md.jinja b/project/docs/{% if insiders %}insiders{% endif %}/index.md.jinja index c55375d..29fec4e 100644 --- a/project/docs/{% if insiders %}insiders{% endif %}/index.md.jinja +++ b/project/docs/{% if insiders %}insiders{% endif %}/index.md.jinja @@ -138,21 +138,10 @@ You can cancel your sponsorship anytime.[^5]
- -{#
- Silver sponsors -

- - - FastAPI - - -

-
#} - -
+
+
+
-
diff --git a/project/docs/{% if insiders %}js{% endif %}/{% if insiders %}insiders.js{% endif %}.jinja b/project/docs/{% if insiders %}js{% endif %}/{% if insiders %}insiders.js{% endif %}.jinja index 03bcb40..8bb6848 100644 --- a/project/docs/{% if insiders %}js{% endif %}/{% if insiders %}insiders.js{% endif %}.jinja +++ b/project/docs/{% if insiders %}js{% endif %}/{% if insiders %}insiders.js{% endif %}.jinja @@ -21,6 +21,26 @@ function getJSON(url, callback) { xhr.send(); } +function updatePremiumSponsors(dataURL, rank) { + let capRank = rank.charAt(0).toUpperCase() + rank.slice(1); + getJSON(dataURL + `/sponsors${capRank}.json`, function (err, sponsors) { + const sponsorsDiv = document.getElementById(`${rank}-sponsors`); + if (sponsors.length > 0) { + let html = ''; + html += `${capRank} sponsors

` + sponsors.forEach(function (sponsor) { + html += ` + + ${sponsor.name} + + ` + }); + html += '

' + sponsorsDiv.innerHTML = html; + } + }); +} + function updateInsidersPage(author_username) { const sponsorURL = `https://github.com/sponsors/${author_username}` const dataURL = `https://raw.githubusercontent.com/${author_username}/sponsors/main`; @@ -48,20 +68,7 @@ function updateInsidersPage(author_username) { } }); }); - getJSON(dataURL + '/sponsorsBronze.json', function (err, sponsors) { - const bronzeSponsors = document.getElementById("bronze-sponsors"); - if (sponsors) { - let html = ''; - html += 'Bronze sponsors

' - sponsors.forEach(function (sponsor) { - html += ` - - ${sponsor.name} - - ` - }); - html += '

' - bronzeSponsors.innerHTML = html; - } - }); + updatePremiumSponsors(dataURL, "gold"); + updatePremiumSponsors(dataURL, "silver"); + updatePremiumSponsors(dataURL, "bronze"); }