Skip to content

Commit 94e2495

Browse files
committed
Made recommend tweaks to MkDocs config to support ReadTheDocs
1 parent e60bd2d commit 94e2495

File tree

6 files changed

+60
-9
lines changed

6 files changed

+60
-9
lines changed

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version: 2
88
build:
99
os: ubuntu-24.04
1010
tools:
11-
python: "3.12"
11+
python: "3"
1212

1313
# Build documentation in the "docs/" directory with MkDocs
1414
mkdocs:

docs/api/index.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
---
2-
render_macros: true
3-
---
4-
51
# API Reference
62

73
These pages document the public API for `cmd2`. If a method, class, function, attribute, or constant is not documented here, consider it private and subject to change. There are many classes, methods, functions, and constants in the source code which do not begin with an underscore but are not documented here. When looking at the source code for this library, you cannot safely assume that because something doesn't start with an underscore, it is a public API.
84

95
If a release of this library changes any of the items documented here, the version number will be incremented according to the [Semantic Version Specification](https://semver.org).
106

11-
This documentation is for `cmd2` version {{ release }}.
12-
137
## Modules
148

159
- [cmd2.Cmd](./cmd.md) - functions and attributes of the main class in this library

docs/javascripts/readthedocs.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
document.addEventListener("DOMContentLoaded", function (event) {
2+
// Trigger Read the Docs' search addon instead of Material MkDocs default
3+
document.querySelector(".md-search__input").addEventListener("focus", (e) => {
4+
const event = new CustomEvent("readthedocs-search-show");
5+
document.dispatchEvent(event);
6+
});
7+
});
8+
9+
// Use CustomEvent to generate the version selector
10+
document.addEventListener("readthedocs-addons-data-ready", function (event) {
11+
const config = event.detail.data();
12+
const versioning = `
13+
<div class="md-version">
14+
<button class="md-version__current" aria-label="Select version">
15+
${config.versions.current.slug}
16+
</button>
17+
18+
<ul class="md-version__list">
19+
${config.versions.active
20+
.map(
21+
(version) => `
22+
<li class="md-version__item">
23+
<a href="${version.urls.documentation}" class="md-version__link">
24+
${version.slug}
25+
</a>
26+
</li>`
27+
)
28+
.join("\n")}
29+
</ul>
30+
</div>`;
31+
32+
document
33+
.querySelector(".md-header__topic")
34+
.insertAdjacentHTML("beforeend", versioning);
35+
});

docs/overrides/main.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% extends "base.html" %} {% block site_meta %} {{ super() }}
2+
<meta name="readthedocs-addons-api-version" content="1" />
3+
{% endblock %}

docs/stylesheets/readthedocs.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
:root {
2+
/* Reduce Read the Docs' flyout font a little bit */
3+
--readthedocs-flyout-font-size: 0.7rem;
4+
5+
/* Reduce Read the Docs' notification font a little bit */
6+
--readthedocs-notification-font-size: 0.8rem;
7+
8+
/* This customization is not yet perfect because we can't change the `line-height` yet. */
9+
/* See https://github.com/readthedocs/addons/issues/197 */
10+
--readthedocs-search-font-size: 0.7rem;
11+
}

mkdocs.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
site_name: cmd2
33
site_description: cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python.
44
site_dir: build/html
5-
site_url: https://cmd2.readthedocs.io/
5+
site_url: !ENV [READTHEDOCS_CANONICAL_URL, https://cmd2.readthedocs.io/]
66

77
# Repository
88
repo_name: cmd2
@@ -16,6 +16,7 @@ copyright: Copyright &copy; 2010-2024, cmd2 contributors.
1616
theme:
1717
name: material
1818
language: en
19+
custom_dir: docs/overrides
1920
icon:
2021
repo: fontawesome/brands/github
2122
logo: material/home
@@ -96,7 +97,6 @@ extra:
9697
link: https://github.com/python-cmd2/cmd2
9798
- icon: simple/pypi
9899
link: https://pypi.org/project/cmd2/
99-
release: "2.5"
100100

101101
# Extensions
102102
# - These are carefully chosen to work with pandoc markdown support for whole document translation
@@ -209,3 +209,11 @@ nav:
209209
- api/plugin_external_test.md
210210
- Meta:
211211
- doc_conventions.md
212+
213+
# Include extra CSS to make some style adjustments
214+
extra_css:
215+
- stylesheets/readthedocs.css
216+
217+
# Include extra JS to setup Read the Docs addons integrations
218+
extra_javascript:
219+
- javascripts/readthedocs.js

0 commit comments

Comments
 (0)