Skip to content

Commit f885e96

Browse files
authored
EthicalAd: better ad position for Docsify (#470)
Show how simple is to add a better ad positioning for a documentation tool that we know. 1. Find the CSS selector that allows to detect the framework 2. Find the CSS selector for the ad position 3. Add small CSS for styling if required ![Screenshot_2024-12-12_12-12-47](https://github.com/user-attachments/assets/7b3dac1f-701f-4e55-83b4-13bb86e96690) Related #447
1 parent b3ebbf6 commit f885e96

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/ethicalads.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,9 @@ div.ethical-footer {
242242
margin-left: 10% !important;
243243
margin-right: 10% !important;
244244
}
245+
246+
/* Docsify */
247+
.ethical-docsify {
248+
margin-left: 10% !important;
249+
margin-right: 10% !important;
250+
}

src/ethicalads.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ export class EthicalAdsAddon extends AddonBase {
135135
placement.classList.add("ethical-alabaster");
136136
placement.classList.add("ethical-docusaurus");
137137

138+
placement.setAttribute("data-ea-type", "readthedocs-sidebar");
139+
placement.setAttribute("data-ea-style", "image");
140+
knownPlacementFound = true;
141+
}
142+
} else if (docTool.isDocsify()) {
143+
selector = "main > aside > div.sidebar-nav";
144+
element = document.querySelector(selector);
145+
146+
if (this.elementAboveTheFold(element)) {
147+
placement.classList.add("ethical-alabaster");
148+
placement.classList.add("ethical-docsify");
149+
138150
placement.setAttribute("data-ea-type", "readthedocs-sidebar");
139151
placement.setAttribute("data-ea-style", "image");
140152
knownPlacementFound = true;

src/utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,21 @@ export class DocumentationTool {
407407
return MKDOCS;
408408
}
409409

410+
if (this.isDocsify()) {
411+
return DOCSIFY;
412+
}
413+
410414
console.debug("We were not able to detect the documentation tool.");
411415
return null;
412416
}
413417

418+
isDocsify() {
419+
if (document.querySelectorAll("head > link[href*=docsify]").length) {
420+
return true;
421+
}
422+
return false;
423+
}
424+
414425
isSphinx() {
415426
return (
416427
this.isSphinxAlabasterLikeTheme() ||

0 commit comments

Comments
 (0)