Compare commits

...

4 Commits

Author SHA1 Message Date
github-actions[bot] f235502234 📝 Update release notes 1 day ago
pre-commit-ci[bot] b40da4f0d5
⬆ [pre-commit.ci] pre-commit autoupdate (#14103) 1 day ago
github-actions[bot] 9aa25fd682 📝 Update release notes 1 day ago
Alejandra 8170860322
♻️ Refactor sponsor image handling (#14102) 1 day ago
  1. 2
      .pre-commit-config.yaml
  2. 12
      docs/en/docs/css/custom.css
  3. 39
      docs/en/docs/js/custom.js
  4. 2
      docs/en/docs/release-notes.md

2
.pre-commit-config.yaml

@ -14,7 +14,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.0
rev: v0.13.1
hooks:
- id: ruff
args:

12
docs/en/docs/css/custom.css

@ -102,7 +102,15 @@ a.announce-link:hover {
align-items: center;
}
.announce-wrapper div.item {
.announce-wrapper #announce-left div.item {
display: none;
}
.announce-wrapper #announce-right {
display: none;
}
.announce-wrapper #announce-right div.item {
display: none;
}
@ -112,7 +120,7 @@ a.announce-link:hover {
top: -10px;
right: 0;
font-size: 0.5rem;
color: #999;
color: #e6e6e6;
background-color: #666;
border-radius: 10px;
padding: 0 10px;

39
docs/en/docs/js/custom.js

@ -135,28 +135,43 @@ async function showRandomAnnouncement(groupId, timeInterval) {
}
}
function hideSponsorOnImageError() {
const sponsorImages = document.querySelectorAll('.sponsor-image');
function handleSponsorImages() {
const announceRight = document.getElementById('announce-right');
if(!announceRight) return;
function hideAnnounceRight() {
if (announceRight) {
announceRight.style.display = 'none';
}
}
const sponsorImages = document.querySelectorAll('.sponsor-image');
sponsorImages.forEach(function(img) {
img.addEventListener('error', function() {
hideAnnounceRight();
const imagePromises = Array.from(sponsorImages).map(img => {
return new Promise((resolve, reject) => {
if (img.complete && img.naturalHeight !== 0) {
resolve();
} else {
img.addEventListener('load', () => {
if (img.naturalHeight !== 0) {
resolve();
} else {
reject();
}
});
img.addEventListener('error', reject);
}
});
});
Promise.all(imagePromises)
.then(() => {
announceRight.style.display = 'block';
showRandomAnnouncement('announce-right', 10000);
})
.catch(() => {
// do nothing
});
}
async function main() {
setupTermynal();
showRandomAnnouncement('announce-left', 5000)
showRandomAnnouncement('announce-right', 10000)
hideSponsorOnImageError();
handleSponsorImages();
}
document$.subscribe(() => {
main()

2
docs/en/docs/release-notes.md

@ -13,6 +13,8 @@ hide:
### Internal
* ⬆ [pre-commit.ci] pre-commit autoupdate. PR [#14103](https://github.com/fastapi/fastapi/pull/14103) by [@pre-commit-ci[bot]](https://github.com/apps/pre-commit-ci).
* ♻️ Refactor sponsor image handling. PR [#14102](https://github.com/fastapi/fastapi/pull/14102) by [@alejsdev](https://github.com/alejsdev).
* 🐛 Fix sponsor display issue by hiding element on image error. PR [#14097](https://github.com/fastapi/fastapi/pull/14097) by [@alejsdev](https://github.com/alejsdev).
* 🐛 Hide sponsor badge when sponsor image is not displayed. PR [#14096](https://github.com/fastapi/fastapi/pull/14096) by [@alejsdev](https://github.com/alejsdev).

Loading…
Cancel
Save