Skip to content

Commit

Permalink
Addons: expose readthedocs.resolver.filename in the API response (#…
Browse files Browse the repository at this point in the history
…11940)

This is required to be able to dynamically update the URLs from the
versions in the flyout when the page is changed using `history` object
(without reloading / SPA) as Docusaurus does.

In that scenario we cannot use the HTML META tag because it was injected
with the old value by CF Worker. Note that the CF Worker is not run
after the initial request on SPA.

The addons frontend will use this attribute to update those URLs
accordingly when the URL changes.

Required by:
* readthedocs/addons#504
  • Loading branch information
humitos authored Jan 28, 2025
1 parent e5c3714 commit 4534f6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions readthedocs/proxito/tests/responses/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
"readthedocs": {
"analytics": {
"code": null
},
"resolver": {
"filename": "/index.html"
}
},
"addons": {
Expand Down
1 change: 1 addition & 0 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ def test_send_project_version_slugs(self):
expected_response = self._get_response_dict("v1")
# Remove `addons.doc_diff` from the response because it's not present when `url=` is not sent
expected_response["addons"].pop("doc_diff")
expected_response["readthedocs"]["resolver"]["filename"] = None

assert self._normalize_datetime_fields(r.json()) == expected_response

Expand Down
3 changes: 3 additions & 0 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ def _v1(self, project, version, build, filename, url, request):
"analytics": {
"code": settings.GLOBAL_ANALYTICS_CODE,
},
"resolver": {
"filename": filename,
},
},
# TODO: the ``features`` is not polished and we expect to change drastically.
# Mainly, all the fields including a Project, Version or Build will use the exact same
Expand Down

0 comments on commit 4534f6a

Please sign in to comment.