Skip to content

Commit

Permalink
Add styles based on the documentation tool
Browse files Browse the repository at this point in the history
Use our heuristic to detect the documentation tool/theme and add specific
`--readthedocs-*` CSS variables based on that for known tools/themes.

Reference: readthedocs/readthedocs.org#11849 (comment)
  • Loading branch information
humitos committed Dec 16, 2024
1 parent f885e96 commit 00f72e0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/flyout.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import { classMap } from "lit/directives/class-map.js";
import { default as objectPath } from "object-path";

import styleSheet from "./flyout.css";
import { AddonBase, addUtmParameters, getLinkWithFilename } from "./utils";
import styleMkDocsMaterial from "./flyout.mkdocs.material.css";
import styleSphinxFuro from "./flyout.sphinx.furo.css";
import {
AddonBase,
addUtmParameters,
getLinkWithFilename,
docTool,
} from "./utils";
import { SPHINX, MKDOCS_MATERIAL } from "./constants";
import {
EVENT_READTHEDOCS_SEARCH_SHOW,
EVENT_READTHEDOCS_FLYOUT_HIDE,
Expand Down Expand Up @@ -387,6 +395,17 @@ export class FlyoutAddon extends AddonBase {
for (const elem of elems) {
elem.loadConfig(config);
}

this.addCustomStyle();
}

addCustomStyle() {
const doctool = docTool.documentationTool;
if (doctool === MKDOCS_MATERIAL) {
document.adoptedStyleSheets.push(styleMkDocsMaterial);
} else if (doctool == SPHINX && docTool.isSphinxFuroLikeTheme()) {
document.adoptedStyleSheets.push(styleSphinxFuro);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/flyout.mkdocs.material.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:root {
/* Reduce Read the Docs' flyout font a little bit */
--readthedocs-flyout-font-size: 0.7rem;
}
4 changes: 4 additions & 0 deletions src/flyout.sphinx.furo.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:root {
/* Reduce Read the Docs' flyout font a little bit */
--readthedocs-flyout-font-size: 0.75rem;
}

0 comments on commit 00f72e0

Please sign in to comment.