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

EthicalAd: use placement-bottom to show the ad above the flyout #295

Merged
merged 4 commits into from
May 21, 2024

Conversation

humitos
Copy link
Member

@humitos humitos commented Apr 24, 2024

This PR enables showing EthicalAds for all projects hosted on Read the Docs and using the new beta addons.

Requires readthedocs/ethical-ad-client#188

@humitos humitos requested a review from a team as a code owner April 24, 2024 14:17
@humitos humitos requested a review from agjohnson April 24, 2024 14:17
humitos added a commit to readthedocs/readthedocs.org that referenced this pull request May 8, 2024
Instead of injecting the EthicalAd in a customized way,
we will injecting it by using the addons approach.

This will be a starting test before enabling this in all the projects that are
using addons.

Requires:
* readthedocs/addons#295
placement.classList.add("raised");

// TODO: find the right last resourse to append (probably not `document.body`)
let main = document.querySelector("[role=main]") || document.body;
Copy link
Member

Choose a reason for hiding this comment

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

I think we've written this "Find main div" logic in a few places -- we should standardize on it. I think search is probably the most built out.

Also should we bring over any of the logic around theme placements (https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/core/static-src/core/js/doc-embed/rtd-data.js#L10-L18)? It's pretty Sphinx specific, but probably still useful to have the ability to smartly place things.

Looking at the old code though, it looks like we're only injecting the ad if we're confident that we know what theme it is, so this is probably a better place to start, and not try to make it too smart and see how it works :)

@davidfischer curious about your thoughts here.

Copy link
Member

Choose a reason for hiding this comment

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

Thinking something like:


Placement preference for RTD ad injection:

Using stickybox image (These float if the screen is wide, automatically):
    * Sidebar like content (`role=sidebar`)
        (Currently we check for sidebar height, and if it's too long, we put it in the footer -- but this is probably not necessary?)
    * Footer like content (`role=footer`)
    * Main body content (`role=main`)
Using text:
    * Fixed footer (Not conflicting with the flyout?)

Though we should also support the HTML elements (<main>) and perhaps use standardized ARIA roles? 🤷 https://www.w3.org/TR/wai-aria/#role_definitions

Copy link
Member Author

Choose a reason for hiding this comment

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

I opened #309 with the logic from the old implementation.

Choose a reason for hiding this comment

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

As to finding the main div, this is what the ad analyzer does. It follows these in order.

As Eric mentioned, we styled the ad based on the theme if we were confident in the theme being RTD-like or Alabaster-like (including RTD-like on mkdocs). This is mostly because Alabaster is "light" while RTD theme is "dark". The current ad client has light and dark theme and that could be used instead if desired. It might allow us to remove some ads-specific code in the RTD codebase. The end goal is just to have the ad look good on a variety of themes regardless of how that actually happens.

humitos and others added 2 commits May 21, 2024 10:31
The logic/idea is borrowed from the old implementation at

https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js#L51

Related https://github.com/readthedocs/addons/pull/295/files#r1600336686

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: humitos <humitos@users.noreply.github.com>
Co-authored-by: Žan Anderle <zan.anderle@gmail.com>
@humitos humitos merged commit c34803f into main May 21, 2024
4 checks passed
@humitos humitos deleted the humitos/ad-stickybox-placement branch May 21, 2024 08:39
humitos added a commit to readthedocs/readthedocs.org that referenced this pull request May 21, 2024
Instead of injecting the EthicalAd in a customized way,
we will injecting it by using the addons approach.

This will be a starting test before enabling this in all the projects that are
using addons.

Requires:
* readthedocs/addons#295
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants