Skip to content

Commit a401586

Browse files
committed
Get features from the footer api
1 parent 75a1444 commit a401586

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

readthedocs/api/v2/views/footer_views.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from readthedocs.builds.constants import LATEST, TAG
1616
from readthedocs.builds.models import Version
1717
from readthedocs.core.utils.extend import SettingsOverrideObject
18-
from readthedocs.projects.models import Project
18+
from readthedocs.projects.models import Project, Feature
1919
from readthedocs.projects.version_handling import (
2020
highest_version,
2121
parse_version_failsafe,
@@ -199,6 +199,19 @@ def _get_context(self):
199199
}
200200
return context
201201

202+
def _get_features(self):
203+
project = self._get_project()
204+
version = self._get_version()
205+
206+
docsearch_disabled = project.has_feature(Feature.DISABLE_SERVER_SIDE_SEARCH)
207+
if not version.is_sphinx_type:
208+
# TODO: Temporal check
209+
docsearch_disabled |= not self.project.has_feature(Feature.ENABLE_MKDOCS_SERVER_SIDE_SEARCH)
210+
211+
return {
212+
'docsearch_disabled': docsearch_disabled,
213+
}
214+
202215
def get(self, request, format=None):
203216
project = self._get_project()
204217
version = self._get_version()
@@ -219,6 +232,7 @@ def get(self, request, format=None):
219232
'version_active': version.active,
220233
'version_compare': version_compare_data,
221234
'version_supported': version.supported,
235+
'features': self._get_features(),
222236
}
223237

224238
# Allow folks to hook onto the footer response for various information

readthedocs/core/static-src/core/js/doc-embed/footer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ function injectFooter(data) {
2222
}
2323

2424

25+
function injectExtraData(data) {
26+
if (typeof window.READTHEDOCS_DATA !=== 'undefined') {
27+
window.READTHEDOCS_DATA.features = data['features'];
28+
}
29+
}
30+
31+
2532
function setupBookmarkCSRFToken() {
2633
function csrfSafeMethod(method) {
2734
// these HTTP methods do not require CSRF protection
@@ -76,6 +83,7 @@ function init() {
7683
versionCompare.init(data.version_compare);
7784
}
7885
injectFooter(data);
86+
injectExtraData(data);
7987
setupBookmarkCSRFToken();
8088
},
8189
error: function () {

readthedocs/doc_builder/backends/mkdocs.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,6 @@ def generate_rtd_data(self, docs_dir, mkdocs_config):
253253
'commit': self.version.project.vcs_repo(self.version.slug).commit,
254254
'global_analytics_code': settings.GLOBAL_ANALYTICS_CODE,
255255
'user_analytics_code': analytics_code,
256-
'features': {
257-
'docsearch_disabled': (
258-
self.project.has_feature(Feature.DISABLE_SERVER_SIDE_SEARCH)
259-
and not self.project.has_feature(Feature.ENABLE_MKDOCS_SERVER_SIDE_SEARCH)
260-
)
261-
},
262256
}
263257

264258
data_ctx = {

readthedocs/doc_builder/backends/sphinx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ def get_config_params(self):
181181
'dont_overwrite_sphinx_context': self.project.has_feature(
182182
Feature.DONT_OVERWRITE_SPHINX_CONTEXT,
183183
),
184-
'docsearch_disabled': self.project.has_feature(Feature.DISABLE_SERVER_SIDE_SEARCH),
185184
}
186185

187186
finalize_sphinx_context_data.send(

readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ context = {
113113
'new_theme': (html_theme == "sphinx_rtd_theme"),
114114
'source_suffix': SUFFIX,
115115
'ad_free': {% if project.show_advertising %}False{% else %}True{% endif %},
116-
'docsearch_disabled': {{ docsearch_disabled }},
117116
'user_analytics_code': '{{ project.analytics_code|default_if_none:'' }}',
118117
'global_analytics_code': '{{ settings.GLOBAL_ANALYTICS_CODE }}',
119118
'commit': {% if project.repo_type == 'git' %}'{{ commit|slice:"8" }}'{% else %}'{{ commit }}'{% endif %},

0 commit comments

Comments
 (0)