Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version warning banner: inject on role="main" or main tag #8079

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion docs/versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,23 @@ you can enable it in the admin section of your docs (:guilabel:`Admin` > :guilab

.. note::

This feature is available only for :doc:`Sphinx projects </intro/getting-started-with-sphinx>`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not true anymore?

Copy link
Member Author

@stsewd stsewd Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this, but I was wrong, thought we injected this from our extension, but this is just JS from the footer. Well, it wasn't a complete lie, since isn't common in mkdocs themes to have div.body or div.document p:

The banner will be injected in an HTML element with the ``main`` role or in the ``main`` tag.
For example:

.. code-block:: html

<div role="main">
<!-- The banner would be injected here -->
...
</div>

.. code-block:: html

<main>
<!-- The banner would be injected here -->
...
</main>


Redirects on root URLs
----------------------
Expand Down
11 changes: 7 additions & 4 deletions readthedocs/core/static-src/core/js/doc-embed/version-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ function init(data) {
.attr('href', currentURL)
.text(data.slug);

var body = $("div.body");
if (!body.length) {
body = $("div.document");
var selectors = ['[role=main]', 'main', 'div.body', 'div.document'];
for (var i = 0; i < selectors.length; i += 1) {
Comment on lines +28 to +29
Copy link
Member

@humitos humitos Apr 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should copy these lines to the sphinx-version-warning extension. Currently, it only uses one selector and the user can change it via a config, but I suppose we could try these same different selectors by default: https://github.com/humitos/sphinx-version-warning/blob/master/versionwarning/_static/js/versionwarning.src.js#L21

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var body = $(selectors[i]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were we ok using let instead of var? Or there was some browser compatibility we were worried about?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, if we're using let, we should also use it (and const) as much as possible.

Copy link
Member

@ericholscher ericholscher Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep it the same as the existing code, to keep things consistent. Then we can change it up when we decide to at the project level.

if (body.length) {
body.prepend(warning);
break;
}
}
body.prepend(warning);
}


Expand Down
Loading