Skip to content

Commit a2a24e4

Browse files
committed
Addons: prepare the backend for the new flyout
Return `addons.flyout.translations` and `addons.flyout.downloads`. Remove `addons.flyout.vcs` for now because we don't have a reliable way to implement it without injecting data into the build which we don't want to do anymore. Related readthedocs/addons#86
1 parent ac9fa94 commit a2a24e4

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

readthedocs/proxito/views/hosting.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def _v0(self, project, version, build, filename):
178178
.only("slug")
179179
.order_by("slug")
180180
)
181+
project_translations = (
182+
project.translations.all().only("language").order_by("language")
183+
)
181184

182185
data = {
183186
"comment": (
@@ -250,23 +253,47 @@ def _v0(self, project, version, build, filename):
250253
"base_page": "",
251254
},
252255
"flyout": {
253-
"translations": [],
256+
"enabled": True,
257+
"translations": [
258+
{
259+
# TODO: name this field "display_name"
260+
"slug": translation.language,
261+
"url": f"/{translation.language}/",
262+
}
263+
for translation in project_translations
264+
],
254265
"versions": [
255266
{
267+
# TODO: name this field "display_name"
256268
"slug": version.slug,
257269
"url": f"/{project.language}/{version.slug}/",
258270
}
259271
for version in versions_active_built
260272
],
261-
"downloads": [],
262-
# TODO: get this values properly
263-
"vcs": {
264-
"url": "https://github.com",
265-
"username": "readthedocs",
266-
"repository": "test-builds",
267-
"branch": version.identifier if version else None,
268-
"filepath": "/docs/index.rst",
269-
},
273+
"downloads": [
274+
{
275+
# TODO: name this field "display_name"
276+
"name": name,
277+
"url": url,
278+
}
279+
for name, url in version.get_downloads(pretty=True).items()
280+
],
281+
# TODO: find a way to get this data in a reliably way.
282+
# We don't have a simple way to map a URL to a file in the repository.
283+
# This feature may be deprecated/removed in this implementation since it relies
284+
# on data injected at build time and sent as `docroot=`, `source_suffix=` and `page=`.
285+
# Example URL:
286+
# /_/api/v2/footer_html/?project=weblate&version=latest&page=index&theme=furo&docroot=/docs/&source_suffix=.rst
287+
# Data injected at:
288+
# https://github.com/rtfd/readthedocs-sphinx-ext/blob/7c60d1646c12ac0b83d61abfbdd5bcd77d324124/readthedocs_ext/_templates/readthedocs-insert.html.tmpl#L23
289+
#
290+
# "vcs": {
291+
# "url": "https://github.com",
292+
# "username": "readthedocs",
293+
# "repository": "test-builds",
294+
# "branch": version.identifier if version else None,
295+
# "filepath": "/docs/index.rst",
296+
# },
270297
},
271298
"search": {
272299
"enabled": True,

0 commit comments

Comments
 (0)