diff --git a/public/_/readthedocs-addons.json b/public/_/readthedocs-addons.json
index 81e3ec3f..ebb8e768 100644
--- a/public/_/readthedocs-addons.json
+++ b/public/_/readthedocs-addons.json
@@ -101,7 +101,7 @@
"load_when_embedded": false
},
"ethicalads": {
- "ad_free": false,
+ "ad_free": true,
"enabled": true,
"publisher": "readthedocs",
"campaign_types": ["community", "house", "paid"],
diff --git a/public/global.css b/public/global.css
new file mode 100644
index 00000000..9ceeab91
--- /dev/null
+++ b/public/global.css
@@ -0,0 +1,5 @@
+/* Theme defaults? */
+:root {
+ --readthedocs-font-size: 10px;
+ --readthedocs-flyout-font-size: 30px;
+}
diff --git a/public/index.html b/public/index.html
index f24ff41a..35ee16e5 100644
--- a/public/index.html
+++ b/public/index.html
@@ -15,6 +15,7 @@
);
+
+
${this.renderHeader()}
${this.renderLanguages()} ${this.renderVersions()}
diff --git a/src/index.js b/src/index.js
index b6827651..b376fd4c 100644
--- a/src/index.js
+++ b/src/index.js
@@ -11,6 +11,7 @@ import * as filetreediff from "./filetreediff";
import * as customscript from "./customscript";
import { default as objectPath } from "object-path";
import {
+ docTool,
domReady,
isEmbedded,
IS_PRODUCTION,
@@ -18,6 +19,8 @@ import {
getMetadataValue,
} from "./utils";
+import { defaultStyleSheet } from "./defaults.js";
+
export function setup() {
const addons = [
flyout.FlyoutAddon,
@@ -50,6 +53,28 @@ export function setup() {
}
}
+ // Apply fixes to variables for individual documentation tools
+ const elementHtml = document.querySelector("html");
+ if (elementHtml) {
+ // Inject styles at the parent DOM to set variables at :root
+ document.adoptedStyleSheets = [defaultStyleSheet];
+
+ // If we detect a documentation tool, set attributes on :root to allow
+ // for CSS selectors to utilize these values.
+ if (docTool.documentationTool) {
+ elementHtml.setAttribute(
+ "data-readthedocs-tool",
+ docTool.documentationTool,
+ );
+ }
+ if (docTool.documentationTheme) {
+ elementHtml.setAttribute(
+ "data-readthedocs-tool-theme",
+ docTool.documentationTheme,
+ );
+ }
+ }
+
return getReadTheDocsConfig(sendUrlParam);
})
.then((config) => {
diff --git a/src/utils.js b/src/utils.js
index e144e051..0a4f3f33 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -2,6 +2,11 @@ import { ajv } from "./data-validation";
import { default as objectPath } from "object-path";
import {
SPHINX,
+ SPHINX_FURO,
+ SPHINX_ALABASTER,
+ SPHINX_READTHEDOCS,
+ SPHINX_IMMATERIAL,
+ MDBOOK,
MKDOCS,
MKDOCS_MATERIAL,
DOCUSAURUS,
@@ -297,6 +302,7 @@ export class DocumentationTool {
constructor() {
this.documentationTool = this.getDocumentationTool();
+ this.documentationTheme = this.getDocumentationTheme();
console.debug(`Documentation tool detected: ${this.documentationTool}`);
}
@@ -411,10 +417,63 @@ export class DocumentationTool {
return DOCSIFY;
}
+ if (this.isMdBook()) {
+ return MDBOOK;
+ }
+
+ if (this.isAntora()) {
+ return ANTORA;
+ }
+
console.debug("We were not able to detect the documentation tool.");
return null;
}
+ getDocumentationTheme() {
+ const documentationTool =
+ this.documentationTool || this.getDocumentationTool();
+
+ if (documentationTool === SPHINX) {
+ if (this.isSphinxAlabasterLikeTheme()) {
+ return SPHINX_ALABASTER;
+ } else if (this.isSphinxReadTheDocsLikeTheme()) {
+ return SPHINX_READTHEDOCS;
+ } else if (this.isSphinxFuroLikeTheme()) {
+ return SPHINX_FURO;
+ } else if (this.isSphinxImmaterialLikeTheme()) {
+ return SPHINX_IMMATERIAL;
+ }
+ }
+
+ // TODO: add the other known themes
+ return null;
+ }
+
+ isAntora() {
+ if (
+ document.querySelectorAll('meta[name="generator"][content^="Antora"]')
+ .length
+ ) {
+ return true;
+ }
+ return false;
+ }
+
+ isMdBook() {
+ //
+ //
+ //
+ // ...
+ if (
+ document?.head?.firstChild?.nextSibling?.textContent.includes(
+ "Book generated using mdBook",
+ )
+ ) {
+ return true;
+ }
+ return false;
+ }
+
isDocsify() {
if (document.querySelectorAll("head > link[href*=docsify]").length) {
return true;
@@ -427,7 +486,8 @@ export class DocumentationTool {
this.isSphinxAlabasterLikeTheme() ||
this.isSphinxReadTheDocsLikeTheme() ||
this.isSphinxFuroLikeTheme() ||
- this.isSphinxBookThemeLikeTheme()
+ this.isSphinxBookThemeLikeTheme() ||
+ this.isSphinxImmaterialLikeTheme()
);
}
@@ -476,7 +536,7 @@ export class DocumentationTool {
// MkDocs version : 1.4.2
// Build Date UTC : 2023-07-11 16:08:07.379780+00:00
// -->
- if (document.lastChild.textContent.includes("MkDocs version :")) {
+ if (document?.lastChild?.textContent.includes("MkDocs version :")) {
return true;
}
return false;
@@ -531,6 +591,18 @@ export class DocumentationTool {
return false;
}
+ isSphinxImmaterialLikeTheme() {
+ if (
+ document.querySelectorAll(
+ 'link[href^="_static/sphinx_immaterial_theme"]',
+ 'a[href="https://github.com/jbms/sphinx-immaterial/"][rel="noopener"]',
+ ).length
+ ) {
+ return true;
+ }
+ return false;
+ }
+
isMaterialMkDocsTheme() {
if (
document.querySelectorAll(