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

Support ads on pallets themes #4499

Merged
merged 2 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions readthedocs/core/static-src/core/js/doc-embed/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var exports = {
THEME_RTD: 'sphinx_rtd_theme',
THEME_ALABASTER: 'alabaster',
THEME_CELERY: 'sphinx_celery',
THEME_MKDOCS_RTD: 'readthedocs',

DEFAULT_PROMO_PRIORITY: 5,
Expand All @@ -15,7 +14,6 @@ var exports = {
exports.PROMO_SUPPORTED_THEMES = [
exports.THEME_RTD,
exports.THEME_ALABASTER,
exports.THEME_CELERY
];

exports.PROMO_TYPES = {
Expand Down
16 changes: 11 additions & 5 deletions readthedocs/core/static-src/core/js/doc-embed/rtd-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ var configMethods = {
return this.get_theme_name() === constants.THEME_RTD;
},

is_alabaster_theme: function () {
// Returns true for Alabaster-like themes (eg. flask, celery)
return this.get_theme_name() === constants.THEME_ALABASTER;
},

theme_supports_promo: function () {
return constants.PROMO_SUPPORTED_THEMES.indexOf(this.get_theme_name()) > -1;
},
Expand All @@ -24,14 +29,15 @@ var configMethods = {
},

get_theme_name: function () {
// Crappy heuristic, but people change the theme name on us. So we have to
// do some duck typing.
if (this.theme !== constants.THEME_RTD) {
// Crappy heuristic, but people change the theme name on us.
// So we have to do some duck typing.
if (this.theme !== constants.THEME_RTD && this.theme !== constants.THEME_ALABASTER) {
if (this.theme === constants.THEME_MKDOCS_RTD) {
return constants.THEME_RTD;
}
if ($('div.rst-other-versions').length === 1) {
} else if ($('div.rst-other-versions').length === 1) {
return constants.THEME_RTD;
} else if ($('div.sphinxsidebar > div.sphinxsidebarwrapper').length === 1) {
return constants.THEME_ALABASTER;
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 unique to alabaster? It feels like something that would be on almost all themes, as it's inherited from the Sphinx basic theme: https://github.com/sphinx-doc/sphinx/blob/master/sphinx/themes/basic/layout.html#L52-L53

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Maybe I need to rethink this. That's a good point.

Copy link
Member

Choose a reason for hiding this comment

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

We are using the same selector to inject the Ads in this line https://github.com/rtfd/readthedocs.org/pull/4499/files#diff-549a0ee75d29b10f27785c6d36e8ce2aR28

So, if the "semantic meaning" of that element from the base theme is what we are selecting, it may makes sense on other themes also.

It would be good to test other themes, though.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, it's a common element across most themes with sidebars. Doing that hueristic selector would definitely let us put ads on more themes, but we should just know that's what we're doing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My immediate goal is to get ads on the pallets themes (which all have different names). Maybe I'll add some constants for "alabaster-like" theme names. From there if we want to iterate and put ads on more themes we can do that in the future.

}
}
return this.theme;
Expand Down
6 changes: 2 additions & 4 deletions readthedocs/core/static-src/core/js/doc-embed/sponsorship.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ function create_sidebar_placement() {
} else if (rtd.is_rtd_theme()) {
selector = 'nav.wy-nav-side > div.wy-side-scroll';
class_name = 'ethical-rtd';
} else if (rtd.get_theme_name() === constants.THEME_ALABASTER ||
rtd.get_theme_name() === constants.THEME_CELERY) {
} else if (rtd.is_alabaster_theme()) {
selector = 'div.sphinxsidebar > div.sphinxsidebarwrapper';
class_name = 'ethical-alabaster';
}
Expand Down Expand Up @@ -66,8 +65,7 @@ function create_footer_placement() {
if (rtd.is_rtd_theme()) {
selector = $('<div />').insertAfter('footer hr');
class_name = 'ethical-rtd';
} else if (rtd.get_theme_name() === constants.THEME_ALABASTER ||
rtd.get_theme_name() === constants.THEME_CELERY) {
} else if (rtd.is_alabaster_theme()) {
selector = 'div.bodywrapper .body';
class_name = 'ethical-alabaster';
}
Expand Down