Skip to content

Search: don't index permalinks #7876

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

Merged
merged 1 commit into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion readthedocs/search/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ def _clean_body(self, body):

This will mutate the original `body`.
"""
# Remove all navigation nodes
nodes_to_be_removed = itertools.chain(
# Navigation nodes
body.css('nav'),
body.css('[role=navigation]'),
body.css('[role=search]'),
# Permalinks
body.css('.headerlink'),
)
for node in nodes_to_be_removed:
node.decompose()
Expand Down
11 changes: 11 additions & 0 deletions readthedocs/search/tests/data/sphinx/in/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ <h2>Sub-title one<a class="headerlink" href="#sub-title-one" title="Permalink to
<div class="section" id="subsub-title">
<h3>Subsub title<a class="headerlink" href="#subsub-title" title="Permalink to this headline">¶</a></h3>
<p>This is a H3 title.</p>

<!-- Figure with permalink and caption -->
<div class="figure align-center" id="id1">
<a class="reference internal image-reference" href="_images/search-analytics-demo.png">
<img alt="Search analytics demo" src="_images/figure.png" style="width: 50%;">
</a>
<p class="caption">
<span class="caption-number">Fig. 4 </span><span class="caption-text">I'm a figure!</span>
<a class="headerlink" href="#id1" title="Permalink to this image">¶</a>
</p>
</div>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion readthedocs/search/tests/data/sphinx/out/page.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"content": "Sphinx configuration file used to build this docs: # -*- coding: utf-8 -*- # Default settings project = 'Test Builds' extensions = [ 'sphinx_autorun', ] latex_engine = 'xelatex' # allow us to build Unicode chars # Include all your settings here html_theme = 'sphinx_rtd_theme' >>> # Build at >>> import datetime >>> datetime.datetime.utcnow() # UTC datetime.datetime(2020, 5, 3, 16, 38, 11, 137311)"
},
{
"content": "This is a H3 title.",
"content": "This is a H3 title. Fig. 4 I'm a figure!",
"id": "subsub-title",
"title": "Subsub title"
}
Expand Down