From 746543e53b13f2df64a853f2da3ca89f996a0db3 Mon Sep 17 00:00:00 2001 From: David Fischer Date: Thu, 5 Jul 2018 11:30:53 -0700 Subject: [PATCH 1/3] Disable the ad block nag for ad-free projects --- readthedocs/core/static-src/core/js/doc-embed/rtd-data.js | 3 ++- readthedocs/core/static-src/core/js/doc-embed/sponsorship.js | 2 +- readthedocs/doc_builder/backends/mkdocs.py | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/readthedocs/core/static-src/core/js/doc-embed/rtd-data.js b/readthedocs/core/static-src/core/js/doc-embed/rtd-data.js index 6336d7f55ed..867c6295b83 100644 --- a/readthedocs/core/static-src/core/js/doc-embed/rtd-data.js +++ b/readthedocs/core/static-src/core/js/doc-embed/rtd-data.js @@ -54,7 +54,8 @@ function get() { var config = Object.create(configMethods); var defaults = { - api_host: 'https://readthedocs.org' + api_host: 'https://readthedocs.org', + ad_free: false, }; $.extend(config, defaults, window.READTHEDOCS_DATA); diff --git a/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js b/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js index c9df2d26e43..11c4f7a0178 100644 --- a/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js +++ b/readthedocs/core/static-src/core/js/doc-embed/sponsorship.js @@ -261,7 +261,7 @@ function init() { error: function (xhr, textStatus, errorThrown) { console.error('Error loading Read the Docs promo'); - if (xhr && xhr.status === 404 && rtd.api_host === 'https://readthedocs.org') { + if (!rtddata.ad_free && xhr && xhr.status === 404 && rtd.api_host === 'https://readthedocs.org') { adblock_admonition(); adblock_nag(); } diff --git a/readthedocs/doc_builder/backends/mkdocs.py b/readthedocs/doc_builder/backends/mkdocs.py index 1468fcd35ed..0815bc5a2c8 100644 --- a/readthedocs/doc_builder/backends/mkdocs.py +++ b/readthedocs/doc_builder/backends/mkdocs.py @@ -175,6 +175,7 @@ def generate_rtd_data(self, docs_dir, mkdocs_config): 'commit': self.version.project.vcs_repo(self.version.slug).commit, 'global_analytics_code': getattr(settings, 'GLOBAL_ANALYTICS_CODE', 'UA-17997319-1'), 'user_analytics_code': analytics_code, + 'ad_free': self.version.project.ad_free, } data_json = json.dumps(readthedocs_data, indent=4) data_ctx = { From 8c3f75ad4425d8c7d25841d9f19457aa1361cc39 Mon Sep 17 00:00:00 2001 From: David Fischer Date: Thu, 5 Jul 2018 11:53:03 -0700 Subject: [PATCH 2/3] Add ad free to the sphinx context --- readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl b/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl index d6eb89ecaa8..48ff74c4f81 100644 --- a/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl +++ b/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl @@ -115,6 +115,7 @@ context = { 'using_theme': (html_theme == "default"), 'new_theme': (html_theme == "sphinx_rtd_theme"), 'source_suffix': SUFFIX, + 'ad_free': {% if project.ad_free %}True{% else %}False{% endif %}, 'user_analytics_code': '{{ project.analytics_code|default_if_none:'' }}', 'global_analytics_code': '{{ settings.GLOBAL_ANALYTICS_CODE }}', {% if project.repo_type == 'git' %} @@ -122,6 +123,7 @@ context = { {% else %} 'commit': '{{ commit }}', {% endif %} + } {# Provide block for extending context data from child template #} From dda848ac7abb3a0b27565a5a2e5c560fe3e573c3 Mon Sep 17 00:00:00 2001 From: David Fischer Date: Thu, 5 Jul 2018 12:14:22 -0700 Subject: [PATCH 3/3] A project can be ad-free by having 'gold_owners' --- readthedocs/doc_builder/backends/mkdocs.py | 2 +- .../doc_builder/templates/doc_builder/conf.py.tmpl | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/readthedocs/doc_builder/backends/mkdocs.py b/readthedocs/doc_builder/backends/mkdocs.py index 0815bc5a2c8..c33931fbe16 100644 --- a/readthedocs/doc_builder/backends/mkdocs.py +++ b/readthedocs/doc_builder/backends/mkdocs.py @@ -172,10 +172,10 @@ def generate_rtd_data(self, docs_dir, mkdocs_config): 'docroot': docs_dir, 'source_suffix': ".md", 'api_host': getattr(settings, 'PUBLIC_API_URL', 'https://readthedocs.org'), + 'ad_free': self.project.ad_free or self.project.gold_owners.exists(), 'commit': self.version.project.vcs_repo(self.version.slug).commit, 'global_analytics_code': getattr(settings, 'GLOBAL_ANALYTICS_CODE', 'UA-17997319-1'), 'user_analytics_code': analytics_code, - 'ad_free': self.version.project.ad_free, } data_json = json.dumps(readthedocs_data, indent=4) data_ctx = { diff --git a/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl b/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl index 48ff74c4f81..5ac457feb25 100644 --- a/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl +++ b/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl @@ -115,15 +115,10 @@ context = { 'using_theme': (html_theme == "default"), 'new_theme': (html_theme == "sphinx_rtd_theme"), 'source_suffix': SUFFIX, - 'ad_free': {% if project.ad_free %}True{% else %}False{% endif %}, + 'ad_free': {% if project.gold_owners.exists or project.ad_free %}True{% else %}False{% endif %}, 'user_analytics_code': '{{ project.analytics_code|default_if_none:'' }}', 'global_analytics_code': '{{ settings.GLOBAL_ANALYTICS_CODE }}', - {% if project.repo_type == 'git' %} - 'commit': '{{ commit|slice:"8" }}', - {% else %} - 'commit': '{{ commit }}', - {% endif %} - + 'commit': {% if project.repo_type == 'git' %}'{{ commit|slice:"8" }}'{% else %}'{{ commit }}'{% endif %}, } {# Provide block for extending context data from child template #}