Skip to content

Commit 8009046

Browse files
authored
Version warning banner: inject on role="main" or main tag (#8079)
Ref pradyunsg/sphinx-basic-ng#12
1 parent feb2040 commit 8009046

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

docs/versions.rst

+17-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,23 @@ you can enable it in the admin section of your docs (:guilabel:`Admin` > :guilab
145145

146146
.. note::
147147

148-
This feature is available only for :doc:`Sphinx projects </intro/getting-started-with-sphinx>`.
148+
The banner will be injected in an HTML element with the ``main`` role or in the ``main`` tag.
149+
For example:
150+
151+
.. code-block:: html
152+
153+
<div role="main">
154+
<!-- The banner would be injected here -->
155+
...
156+
</div>
157+
158+
.. code-block:: html
159+
160+
<main>
161+
<!-- The banner would be injected here -->
162+
...
163+
</main>
164+
149165

150166
Redirects on root URLs
151167
----------------------

readthedocs/core/static-src/core/js/doc-embed/version-compare.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ function init(data) {
2525
.attr('href', currentURL)
2626
.text(data.slug);
2727

28-
var body = $("div.body");
29-
if (!body.length) {
30-
body = $("div.document");
28+
var selectors = ['[role=main]', 'main', 'div.body', 'div.document'];
29+
for (var i = 0; i < selectors.length; i += 1) {
30+
var body = $(selectors[i]);
31+
if (body.length) {
32+
body.prepend(warning);
33+
break;
34+
}
3135
}
32-
body.prepend(warning);
3336
}
3437

3538

0 commit comments

Comments
 (0)