Skip to content

Commit e3ecf3d

Browse files
authored
Addons: allow users to define root_selector from the WebUI (#11181)
* Addons: allow users to define `root_selector` from the WebUI We are using `[role=main]` as the default root selector. However, there are documentation tools that don't define it. This PR exposes the `doc_diff_root_selector` to users to they can define a custom selector that work for their documentation tool. Reference readthedocs/addons#263 * Minor fix to tests * Add a placeholder to show the default value * Update migrations * Migrations fixed
1 parent ed1f564 commit e3ecf3d

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed

readthedocs/projects/forms.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ class Meta:
587587
"project",
588588
"analytics_enabled",
589589
"doc_diff_enabled",
590+
"doc_diff_root_selector",
590591
"external_version_warning_enabled",
591592
"flyout_enabled",
592593
"flyout_sorting",
@@ -605,6 +606,11 @@ class Meta:
605606
"Show a notification on non-stable and latest versions"
606607
),
607608
}
609+
widgets = {
610+
"doc_diff_root_selector": forms.TextInput(
611+
attrs={"placeholder": "[role=main]"}
612+
),
613+
}
608614

609615
def __init__(self, *args, **kwargs):
610616
self.project = kwargs.pop("project", None)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Django 4.2.10 on 2024-03-12 09:34
2+
3+
from django.db import migrations, models
4+
from django_safemigrate import Safe
5+
6+
7+
class Migration(migrations.Migration):
8+
safe = Safe.before_deploy
9+
10+
dependencies = [
11+
("projects", "0118_addons_flyout_sorting"),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name="addonsconfig",
17+
name="flyout_sorting_custom_pattern",
18+
field=models.CharField(
19+
blank=True,
20+
default=None,
21+
help_text='Sorting pattern supported by BumpVer (<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
22+
max_length=32,
23+
null=True,
24+
),
25+
),
26+
migrations.AlterField(
27+
model_name="historicaladdonsconfig",
28+
name="flyout_sorting_custom_pattern",
29+
field=models.CharField(
30+
blank=True,
31+
default=None,
32+
help_text='Sorting pattern supported by BumpVer (<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
33+
max_length=32,
34+
null=True,
35+
),
36+
),
37+
]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Generated by Django 4.2.10 on 2024-03-04 12:02
2+
3+
from django.db import migrations, models
4+
from django_safemigrate import Safe
5+
6+
7+
class Migration(migrations.Migration):
8+
safe = Safe.before_deploy
9+
dependencies = [
10+
("projects", "0119_alter_addonsconfig_flyout_sorting_custom_pattern_and_more"),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name="addonsconfig",
16+
name="doc_diff_root_selector",
17+
field=models.CharField(
18+
blank=True,
19+
help_text="CSS selector for the main content of the page",
20+
max_length=128,
21+
null=True,
22+
),
23+
),
24+
migrations.AlterField(
25+
model_name="historicaladdonsconfig",
26+
name="doc_diff_root_selector",
27+
field=models.CharField(
28+
blank=True,
29+
help_text="CSS selector for the main content of the page",
30+
max_length=128,
31+
null=True,
32+
),
33+
),
34+
]

readthedocs/projects/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ class AddonsConfig(TimeStampedModel):
173173
doc_diff_enabled = models.BooleanField(default=True)
174174
doc_diff_show_additions = models.BooleanField(default=True)
175175
doc_diff_show_deletions = models.BooleanField(default=True)
176-
doc_diff_root_selector = models.CharField(null=True, blank=True, max_length=128)
176+
doc_diff_root_selector = models.CharField(
177+
null=True,
178+
blank=True,
179+
max_length=128,
180+
help_text="CSS selector for the main content of the page",
181+
)
177182

178183
# External version warning
179184
external_version_warning_enabled = models.BooleanField(default=True)

readthedocs/proxito/tests/responses/v0.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"doc_diff": {
104104
"enabled": true,
105105
"base_url": "https://project.dev.readthedocs.io/en/latest/index.html",
106-
"root_selector": "[role=main]",
106+
"root_selector": null,
107107
"inject_styles": true,
108108
"base_host": "",
109109
"base_page": ""

readthedocs/proxito/views/hosting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def _v0(self, project, version, build, filename, url, user):
485485
)
486486
if filename
487487
else None,
488-
"root_selector": "[role=main]",
488+
"root_selector": project.addons.doc_diff_root_selector,
489489
"inject_styles": True,
490490
# NOTE: `base_host` and `base_page` are not required, since
491491
# we are constructing the `base_url` in the backend instead

0 commit comments

Comments
 (0)