Skip to content

Commit

Permalink
refactor: Update premium sponsors display
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Mar 13, 2024
1 parent 60e623c commit aabb40a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
17 changes: 3 additions & 14 deletions project/docs/{% if insiders %}insiders{% endif %}/index.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,10 @@ You can cancel your sponsorship anytime.[^5]

<hr>
<div class="premium-sponsors">

{# <div id="silver-sponsors">
<b>Silver sponsors</b>
<p>
<a href="https://fastapi.tiangolo.com/" target="_blank" title="FastAPI">
<img alt="FastAPI" src="https://raw.githubusercontent.com/squidfunk/mkdocs-material/master/.github/assets/sponsors/sponsor-fastapi.png">
</a>
</p>
</div> #}

<div id="bronze-sponsors"></div>
<div id="gold-sponsors"></div>
<div id="silver-sponsors"></div>
<div id="bronze-sponsors"></div>
</div>

<hr>

<div id="sponsors"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 += `<b>${capRank} sponsors</b><p>`
sponsors.forEach(function (sponsor) {
html += `
<a href="${sponsor.url}" target="_blank" title="${sponsor.name}">
<img alt="${sponsor.name}" src="${sponsor.image}" style="height: ${sponsor.imageHeight}px;">
</a>
`
});
html += '</p>'
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`;
Expand Down Expand Up @@ -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 += '<b>Bronze sponsors</b><p>'
sponsors.forEach(function (sponsor) {
html += `
<a href="${sponsor.url}" target="_blank" title="${sponsor.name}">
<img alt="${sponsor.name}" src="${sponsor.image}" style="height: ${sponsor.imageHeight}px;">
</a>
`
});
html += '</p>'
bronzeSponsors.innerHTML = html;
}
});
updatePremiumSponsors(dataURL, "gold");
updatePremiumSponsors(dataURL, "silver");
updatePremiumSponsors(dataURL, "bronze");
}

0 comments on commit aabb40a

Please sign in to comment.