-
Notifications
You must be signed in to change notification settings - Fork 12
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
API: use <meta>
to define supported API version and trigger CustomEvent
#64
Conversation
00120b5
to
f3eaa7a
Compare
Let users to define `<meta name="readthedocs-api-version" content="1.0">` to tell Read the Docs client what is the API scheme version supported by them. When our client request the API data, if the `api_version` returned does not match with the one expected by the user, another request is done to force a particular API scheme version. Then, we dispatch a `readthedocsdataready` custom event, to let our users know this data is ready to be consumed by their own integrations. Closes #60 Closes #61
f3eaa7a
to
2fdb6c8
Compare
@pradyunsg 👋🏼 -- I'm pinging you in this PR because this is the initial implementation for the pattern that we talked at PyCon to keep the integration stable as much as possible. I'd appreciate any feedback you may have here. Let me know if connecting to the Feel free to suggest any change you consider, from naming to full re-designing of the pattern 😉 |
Haven't reviewed the logic/code but the description sounds great! |
This new header will force the API endpoint to return a specific JSON version schema without taking into consideration the any other header. The idea behind this is to allow theme authors guarrantees about the JSON scheme they are expecting; without stopping us to move forward with potential changes required to the API response when adding new features/addons/etc. Related readthedocs/addons#64
… humitos/custom-event
Initial experimentation to use the `CustomEvent` triggered by the addons called `readthedocsdataready` event (from readthedocs/addons#64) to build the Read the Docs flyout being integrated into the theme keeping the original look & feel. * Related: readthedocs/addons#64 * Closes #1523
@pradyunsg I did a POC on the Read the Docs Sphinx theme using this idea of listening to a |
<meta>
to define supported API version<meta>
to define supported API version and trigger CustomEvent
* API: accept `X-RTD-Hosting-Integrations-API-Version` This new header will force the API endpoint to return a specific JSON version schema without taking into consideration the any other header. The idea behind this is to allow theme authors guarrantees about the JSON scheme they are expecting; without stopping us to move forward with potential changes required to the API response when adding new features/addons/etc. Related readthedocs/addons#64 * Remove old test * Use text for `api_version`, since it could be something like `0.1.2`
… humitos/custom-event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noted how we could improve the promise flow here, the most important point is probably to be ensuring we stop the promise when we hit an error state though.
… humitos/custom-event
Integrate the new Read the Docs Addons JavaScript into the Python Docs Sphinx theme to render versions and languages selector nicely. References: * Discuss thread: https://discord.com/channels/935215565872693329/1159601953265942589 * Implementation of Addons JavaScript `CustomEvent`: readthedocs/addons#64
Integrate the new Read the Docs Addons JavaScript into the Python Docs Sphinx theme to render versions and languages selector nicely. References: * Discord thread: https://discord.com/channels/935215565872693329/1159601953265942589 * Implementation of Addons JavaScript `CustomEvent`: readthedocs/addons#64 * Conversation about using Read the Docs: python/docs-community#5
I updated this PR with the latest changes on I opened a POC on the CPython repository that requires the work from this PR to render the language and version selector on their documentation: python/cpython#116966 I've been talking to them via Discord and they are thinking about merging that PR soon to continue with the experimentation about hosting their docs on Read the Docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Overall, I would still point you towards using Promise instances more often, as this pattern does help tame promise chaining and nesting rather well.
Follow Anthony's suggestion from #64 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The promise logic change looks good 👍
Edit: oookay, I was confused why the logic didn't seem different here. I saw the commit eb550b above and thought it was in this PR 😅
I just realized this from a commit in #286 instead. I think we can merge this and tune the logic afterwards.
Implements the changes in the API made in readthedocs/readthedocs.org#11205. We need to merge that PR and deploy addons together with the changes in this PR. In this PR there are mainly no changes in the logic. The most important thing to mention here is that we are standardizing the usage of the API response and pinning to `v1` now (we were using `v0-alpha`). This means: - we will be exposing the `v1` to users via the js custom event (see #64) - we are using standard/shared APIv3 serializers for resources for this `/addons/` endpoint - any breaking change we have to do in the future it will increase the API response version I'm not sure there are too much to review here, but I'd appreciate at least a quick look at these changes. I'm happy to answer some questions you may have here or on the underlying PR about the API response changes. ### Related: * Closes #132 * Unblocks #265 * Unblocks theme integration (our theme and CPython's one) * Requires readthedocs/readthedocs.org#11205 --------- Co-authored-by: Anthony <aj@ohess.org>
Follow Anthony's suggestion from #64 (comment)
…into humitos/custom-event
🎉 |
* Addons: integrate with new beta addons flyout Initial experimentation to use the `CustomEvent` triggered by the addons called `readthedocsdataready` event (from readthedocs/addons#64) to build the Read the Docs flyout being integrated into the theme keeping the original look & feel. * Related: readthedocs/addons#64 * Closes #1523 * `READTHEDOCS` variable has to be passed to the `html_context` This is because we are not executing the Read the Docs magic that modifies the `conf.py` file on the fly :/ * Update code to match the latest changes * Use `.join` to avoid rendering the Array with `,` * Update code to use the v1 API structure response * Don't auto-remove the original flyout This can be disabled per-project by using the settings UI from the dashboard. * Join the values to avoid strange `,`s * Support translations Use the current pattern to translate string generated for the flyout. * Remove HTML tags for testing * Show "Search" section on flyout * Render footer * Add some styling * TODO comments to work on * add `div.injected` * Apply suggestions from code review Co-authored-by: Anthony <aj@ohess.org> * Translate privacy policy * Add `.rtd-current-item` class to selected version/language * Refactor code to show sections only if there is content * Epub instead of EPUB for backward compatibility * Show the modal when clicking on the "Search docs" from navbar * Remove privacy policy link from flyout * Add UTM analytics * Move CSS style into SASS file * Move the `script` tag into its own file * Rename JS file to mark it as a Sphinx template * Build css/js files Run `npm ci` and `npm run build` using NodeJS 14.20.1. * Add the JS template in the package --------- Co-authored-by: Anthony <aj@ohess.org>
Let users to define
<meta name="readthedocs-api-version" content="1.0">
to tell Read the Docs client what is the API scheme version supported by them.When our client request the API data, if the
api_version
returned does not match with the one expected by the user, another request is done to force a particular API scheme version.Then, we dispatch a
readthedocsdataready
custom eventand expose, to let our users know this data is ready to be consumed by their own integrations.window.readthedocs
Closes #60
Closes #61
Closes #17
Closes readthedocs/readthedocs.org#9957
Closes #250