Skip to content

Commit

Permalink
EthicalAd: show the ad more integrated on Sphinx's furo theme (#403)
Browse files Browse the repository at this point in the history
Show the ad in the toc tree container (right bar). I tried adding it to
the left bar similar to our own theme, but since they use a narrow (in
width) bar, it doesn't look good because it touches the borders.


![Screenshot_2024-10-11_19-30-10](https://github.com/user-attachments/assets/0d250613-e3dc-48d7-8c7d-931da41c2f04)
  • Loading branch information
humitos authored Oct 14, 2024
1 parent 26b1078 commit fb330b4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dist/readthedocs-addons.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/readthedocs-addons.js.map

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/ethicalads.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ export class EthicalAdsAddon extends AddonBase {
return false;
}

isFuroLikeTheme() {
if (
document.querySelectorAll('link[href^="_static/styles/furo.css"]')
.length === 1
) {
return true;
}
return false;
}

isSphinxBookThemeLikeTheme() {
if (
document.querySelectorAll(
Expand Down Expand Up @@ -142,6 +152,21 @@ export class EthicalAdsAddon extends AddonBase {
placement.classList.add("ethical-dark-theme");
knownPlacementFound = true;
}
} else if (this.isFuroLikeTheme()) {
// NOTE: The code to handle furo theme shouldn't be required,
// since furo uses explicit placement.
// However, the Jinja context variable READTHEDOCS is not injected anymore,
// and furo does not includes the explicit placement due to this.
// This is a temporal solution while they fix this.
selector = ".sidebar-tree";
element = document.querySelector(selector);

if (this.elementAboveTheFold(element)) {
placement.classList.add("ethical-alabaster");
placement.setAttribute("data-ea-type", "readthedocs-sidebar");
placement.setAttribute("id", "furo-sidebar-ad-placement");
knownPlacementFound = true;
}
} else if (this.isSphinxBookThemeLikeTheme()) {
selector = ".sidebar-primary-items__start.sidebar-primary__section";
element = document.querySelector(selector);
Expand Down

0 comments on commit fb330b4

Please sign in to comment.