-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adddons: allow injecting an "always live" JavaScript file (#11758)
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 1. [Tell Sphinx to include `static` folder](https://github.com/readthedocs/test-builds/blob/full-feature/docs/conf.py#L25) 2. [Include a `readthedocs.js` file in your project](https://github.com/readthedocs/test-builds/blob/full-feature/docs/static/readthedocs.js) 3. Make `AddonsConfig.userjsfile_src` to be `/en/full-feature/readthedocs.js` from addons admin UX The console will render the following: ![Screenshot_2024-11-11_18-13-59](https://github.com/user-attachments/assets/9fa46525-3b20-4d88-9950-f0a93a1199ab) Related #11474 Related readthedocs/addons#431
- Loading branch information
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
readthedocs/projects/migrations/0135_addons_customscript.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 4.2.16 on 2024-11-13 13:34 | ||
|
||
from django.db import migrations, models | ||
from django_safemigrate import Safe | ||
|
||
|
||
class Migration(migrations.Migration): | ||
safe = Safe.before_deploy | ||
|
||
dependencies = [ | ||
('projects', '0134_addons_load_when_embedded_notnull'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='addonsconfig', | ||
name='customscript_enabled', | ||
field=models.BooleanField(default=False, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='addonsconfig', | ||
name='customscript_src', | ||
field=models.CharField(blank=True, help_text='URL to a JavaScript file to inject at serve time', max_length=512, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='historicaladdonsconfig', | ||
name='customscript_enabled', | ||
field=models.BooleanField(default=False, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='historicaladdonsconfig', | ||
name='customscript_src', | ||
field=models.CharField(blank=True, help_text='URL to a JavaScript file to inject at serve time', max_length=512, null=True), | ||
), | ||
] |
25 changes: 25 additions & 0 deletions
25
readthedocs/projects/migrations/0136_addons_customscript_notnull.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 4.2.16 on 2024-11-13 13:36 | ||
|
||
from django.db import migrations, models | ||
from django_safemigrate import Safe | ||
|
||
|
||
class Migration(migrations.Migration): | ||
safe = Safe.after_deploy | ||
|
||
dependencies = [ | ||
('projects', '0135_addons_customscript'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='addonsconfig', | ||
name='customscript_enabled', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AlterField( | ||
model_name='historicaladdonsconfig', | ||
name='customscript_enabled', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters