-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Adddons: allow injecting an "always live" JavaScript file #11758
base: humitos/addons-embedded-http-header
Are you sure you want to change the base?
Conversation
We talked about giving users a way to inject a JavaScript file they control using our Cloudflare Worker infrastructure to allow them manipulate frozen documentations. This could be used in different ways to fix bugs or add features to a particular frozen set of docs or even to all the versions. The user can make usage of API data to filter by version or not (e.g. `if (versions.current == "v3.0") { .. do something ...} `) The script could live in Read the Docs itself using a relative URL, or outside it, using an absolute URL.
This is a new addon that allow users to inject a specific JavaScript file to all the versions to all the documentation pages to allow them to fix issues in old "frozen" (not able to re-build) versions. Requires readthedocs/readthedocs.org#11758
I changed this approach to simplify it a little. Instead of using an HTTP header file, I implemented this as an addon. We are returning I did the addon implementation at readthedocs/addons#431, and I like this implementation more since it follows the pattern we already have and it doesn't require complicated HTTP headers. |
The feature naming "User JS" could be more accurate I feel, these scripts aren't connected to users, especially on commercial where projects don't really have users -- only teams and members. This feels more like a custom script or extra script or some other phrase that signals usage more.
I think it's fine to start here. We might eventually consider doing this automatically for the user though. If we made this field the source of the JS file instead of a URL, we could easily serve the file for the user (under |
I like custom script 👍🏼 . I will update the code with that name.
Yeah, that makes sense to me. I didn't want to complicate things by uploading a file, but maybe a TextField is enough? However, it will immediately put a lot more pressure on the Read the Docs side for this. People will start asking for a nicer editor for that field, and also versioning, etc. I think this could escalate pretty quickly. I'm not opposed, but I think we can explore this more in a future iteration. |
Yeah, I'd say we could explore a textfield, nothing fancy. I don't think we need to take on any additional work around an editor UI or versioning though, that seems like a lot for a minor feature. I'd only take on an editor interface if we had another use for it somewhere else in the UI. I'd sooner allow an API POST to update the addons config and let users manage their project's custom JS that way. |
Do you mean in this PR or in the next iteration? |
Maybe do we want to have both? |
Sorry, yeah later, I think it's fine to start with just a URL
Great point, supporting both doesn't seem hard. This sounds like a good plan for later |
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 is a really nice feature 💯. If we're gonna ship it, we should put some docs together, and probably a couple examples of when this is useful.
|
||
|
||
class Migration(migrations.Migration): | ||
safe = Safe.after_deploy |
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.
Nice making them nullable 💯
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.
customscript_enabled is not nullable, so this will still break when creating a new addons object.
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 previous migration makes it nullable during deploy, and then marks it not nullable after, which I thought would work?
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.
ah, I didn't see there were two migrations. I guess Django will ask for a default value when running this migration (for the objects that were created while the field was null).
We talked about giving users a way to inject a JavaScript file they control using our Cloudflare Worker infrastructure to allow them manipulate frozen documentations.
This could be used in different ways to fix bugs or add features to a particular frozen set of docs or even to all the versions. The user can make usage of API data to filter by version or not
(e.g.
if (versions.current == "v3.0") { .. do something ...}
)The script could live in Read the Docs itself using a relative URL, or outside it, using an absolute URL.
Example using Sphinx
static
folderreadthedocs.js
file in your projectAddonsConfig.userjsfile_src
to be/en/full-feature/readthedocs.js
from addons admin UXThe console will render the following:
Related #11474
Related readthedocs/addons#431