|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import os |
| 6 | +import re |
5 | 7 | import sys |
6 | 8 | from pathlib import Path |
7 | 9 |
|
| 10 | +from sphinx.application import Sphinx |
| 11 | + |
| 12 | +autoclass_content = "both" |
| 13 | + |
8 | 14 | ROOT = Path(__file__).resolve().parents[1] |
9 | 15 | sys.path.insert(0, str(ROOT / "src")) |
10 | 16 |
|
|
28 | 34 | autosummary_imported_members = True |
29 | 35 | nitpicky = True |
30 | 36 |
|
31 | | -templates_path: list[str] = [] |
| 37 | +templates_path = ["_templates"] |
32 | 38 | exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] |
33 | 39 |
|
34 | | -try: |
35 | | - import sphinx_rtd_theme # noqa: F401 |
36 | | - |
| 40 | +if os.environ.get("READTHEDOCS") == "True": |
37 | 41 | html_theme = "sphinx_rtd_theme" |
38 | | -except ImportError: |
39 | | - html_theme = "alabaster" |
| 42 | +else: |
| 43 | + try: |
| 44 | + import sphinx_rtd_theme # noqa: F401 |
40 | 45 |
|
41 | | -html_static_path: list[str] = [] |
| 46 | + html_theme = "sphinx_rtd_theme" |
| 47 | + except ImportError: |
| 48 | + html_theme = "alabaster" |
| 49 | + |
| 50 | +html_static_path = ["_static"] |
| 51 | +html_css_files = ["custom.css"] |
42 | 52 | html_logo = "drc.png" |
43 | | -html_theme_options = {"logo_only": True} |
| 53 | +html_title = project |
| 54 | +if html_theme == "sphinx_rtd_theme": |
| 55 | + html_theme_options = {"logo_only": False} |
| 56 | +else: |
| 57 | + html_theme_options = {} |
| 58 | + |
| 59 | +_VIEWPORT_META_RE = re.compile(r'<meta name="viewport"[^>]*>', re.IGNORECASE) |
| 60 | + |
| 61 | + |
| 62 | +def _dedupe_viewport_meta( |
| 63 | + app: object, |
| 64 | + pagename: str, |
| 65 | + templatename: str, |
| 66 | + context: dict[str, object], |
| 67 | + doctree: object, |
| 68 | +) -> None: |
| 69 | + """Keep one viewport tag by removing extra entries from Sphinx metatags.""" |
| 70 | + del app, pagename, templatename, doctree |
| 71 | + metatags = context.get("metatags") |
| 72 | + if isinstance(metatags, str): |
| 73 | + context["metatags"] = _VIEWPORT_META_RE.sub("", metatags) |
| 74 | + |
| 75 | + |
| 76 | +def setup(app: Sphinx) -> None: |
| 77 | + """Register build-time hooks.""" |
| 78 | + app.connect("html-page-context", _dedupe_viewport_meta) |
0 commit comments