-
-
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
Addons: make default root CSS selector a shared option #11767
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Generated by Django 4.2.16 on 2024-11-14 13:16 | ||
|
||
from django.db import migrations, models | ||
from django_safemigrate import Safe | ||
|
||
|
||
class Migration(migrations.Migration): | ||
safe = Safe.before_deploy | ||
|
||
dependencies = [ | ||
('projects', '0132_addons_linkpreviews_fields'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='addonsconfig', | ||
name='doc_diff_root_selector', | ||
), | ||
migrations.RemoveField( | ||
model_name='addonsconfig', | ||
name='linkpreviews_doctool_name', | ||
), | ||
migrations.RemoveField( | ||
model_name='addonsconfig', | ||
name='linkpreviews_doctool_version', | ||
), | ||
migrations.RemoveField( | ||
model_name='addonsconfig', | ||
name='linkpreviews_root_selector', | ||
), | ||
migrations.RemoveField( | ||
model_name='historicaladdonsconfig', | ||
name='doc_diff_root_selector', | ||
), | ||
migrations.RemoveField( | ||
model_name='historicaladdonsconfig', | ||
name='linkpreviews_doctool_name', | ||
), | ||
migrations.RemoveField( | ||
model_name='historicaladdonsconfig', | ||
name='linkpreviews_doctool_version', | ||
), | ||
migrations.RemoveField( | ||
model_name='historicaladdonsconfig', | ||
name='linkpreviews_root_selector', | ||
), | ||
migrations.AddField( | ||
model_name='addonsconfig', | ||
name='options_doctool_name', | ||
field=models.CharField(blank=True, choices=[('sphinx', 'Sphinx'), ('other', 'Other')], help_text='Name of the documentation tool used by this project', max_length=128, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='addonsconfig', | ||
name='options_doctool_root_selector', | ||
field=models.CharField(blank=True, help_text='CSS selector for the main content of the page', max_length=128, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='historicaladdonsconfig', | ||
name='options_doctool_name', | ||
field=models.CharField(blank=True, choices=[('sphinx', 'Sphinx'), ('other', 'Other')], help_text='Name of the documentation tool used by this project', max_length=128, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='historicaladdonsconfig', | ||
name='options_doctool_root_selector', | ||
field=models.CharField(blank=True, help_text='CSS selector for the main content of the page', max_length=128, null=True), | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting that these are add/remove operations, and feel like they could be alters instead. It's probably not necessary, the docdiff selector is probably the only one potentially used by users so far. Maybe a migration is necessary for this at least? |
||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,10 +144,11 @@ class AddonsConfig(TimeStampedModel): | |
Everything is enabled by default. | ||
""" | ||
|
||
DOC_DIFF_DEFAULT_ROOT_SELECTOR = "[role=main]" | ||
LINKPREVIEWS_DEFAULT_ROOT_SELECTOR = "[role=main] a.internal" | ||
LINKPREVIEWS_DOCTOOL_NAME_CHOICES = ( | ||
DEFAULT_ROOT_SELECTOR = ":is([role=main],main,div.body,div.document)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
DOCTOOL_NAME_CHOICES = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like we're going to want more of these over time, and some way to have users input one, but we can start with this for now I guess. |
||
("sphinx", "Sphinx"), | ||
("mkdocs", "MkDocs"), | ||
("docusaurus", "Docusaurus"), | ||
("other", "Other"), | ||
) | ||
|
||
|
@@ -167,6 +168,20 @@ class AddonsConfig(TimeStampedModel): | |
help_text="Enable/Disable all the addons on this project", | ||
) | ||
|
||
options_doctool_name = models.CharField( | ||
choices=DOCTOOL_NAME_CHOICES, | ||
null=True, | ||
blank=True, | ||
max_length=128, | ||
help_text="Name of the documentation tool used by this project", | ||
) | ||
options_doctool_root_selector = models.CharField( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a UX issue, but it feels weird to expose these at the top level of Addons. I think most users don't have any idea what to do with this, especially since the UI has help_text hidden, and there's no HTML placeholder. If we're going to be surfacing this so prominently, we definitely need more UI to guide users about what to put here, but I'm pretty skeptical that most users will need to adjust this, and will know when and how to do it? |
||
null=True, | ||
blank=True, | ||
max_length=128, | ||
help_text="CSS selector for the main content of the page", | ||
) | ||
|
||
# Analytics | ||
|
||
# NOTE: we keep analytics disabled by default to save resources. | ||
|
@@ -177,12 +192,6 @@ class AddonsConfig(TimeStampedModel): | |
doc_diff_enabled = models.BooleanField(default=True) | ||
doc_diff_show_additions = models.BooleanField(default=True) | ||
doc_diff_show_deletions = models.BooleanField(default=True) | ||
doc_diff_root_selector = models.CharField( | ||
null=True, | ||
blank=True, | ||
max_length=128, | ||
help_text="CSS selector for the main content of the page", | ||
) | ||
|
||
# EthicalAds | ||
ethicalads_enabled = models.BooleanField(default=True) | ||
|
@@ -226,18 +235,6 @@ class AddonsConfig(TimeStampedModel): | |
|
||
# Link Previews | ||
linkpreviews_enabled = models.BooleanField(default=False) | ||
linkpreviews_root_selector = models.CharField(null=True, blank=True, max_length=128) | ||
linkpreviews_doctool_name = models.CharField( | ||
choices=LINKPREVIEWS_DOCTOOL_NAME_CHOICES, | ||
null=True, | ||
blank=True, | ||
max_length=128, | ||
) | ||
linkpreviews_doctool_version = models.CharField( | ||
null=True, | ||
blank=True, | ||
max_length=128, | ||
) | ||
|
||
|
||
class AddonSearchFilter(TimeStampedModel): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,21 +111,16 @@ def _get_main_node(self, html): | |
so they are children of the same parent node. | ||
- Return the body element itself if all checks above fail. | ||
""" | ||
body = html.body | ||
main_node = body.css_first("[role=main]") | ||
if main_node: | ||
return main_node | ||
Comment on lines
-114
to
-117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that we had role=main for old versions of sphinx, they may see some extra content indexed now. |
||
from readthedocs.projects.models import AddonsConfig | ||
|
||
main_node = body.css_first("main") | ||
body = html.body | ||
main_node = body.css_first( | ||
self.project.addons.options_doctool_root_selector | ||
or AddonsConfig.DEFAULT_ROOT_SELECTOR | ||
) | ||
if main_node: | ||
return main_node | ||
|
||
# TODO: this could be done in smarter way, | ||
# checking for common parents between all h nodes. | ||
first_header = body.css_first("h1") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another place we're losing this h1 logic as a fallback. Seems important, since otherwise we're changing how it works again. |
||
if first_header: | ||
return self._get_header_container(first_header).parent | ||
|
||
return body | ||
|
||
def _get_header_container(self, h_tag): | ||
|
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.
Seems this part isn't in the new selector? It's not backwards compat, so we should probably keep this here for now?