Skip to content

Commit 30c0636

Browse files
authored
Search: don't index permalinks (#7876)
Permalinks can be inside sections as well. You can see an example here, second result https://docs.readthedocs.io/en/stable/server-side-search.html?rtd_search=analytics#analytics
1 parent 2edf3ea commit 30c0636

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

readthedocs/search/parsers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,13 @@ def _clean_body(self, body):
166166
167167
This will mutate the original `body`.
168168
"""
169-
# Remove all navigation nodes
170169
nodes_to_be_removed = itertools.chain(
170+
# Navigation nodes
171171
body.css('nav'),
172172
body.css('[role=navigation]'),
173173
body.css('[role=search]'),
174+
# Permalinks
175+
body.css('.headerlink'),
174176
)
175177
for node in nodes_to_be_removed:
176178
node.decompose()

readthedocs/search/tests/data/sphinx/in/page.html

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ <h2>Sub-title one<a class="headerlink" href="#sub-title-one" title="Permalink to
1717
<div class="section" id="subsub-title">
1818
<h3>Subsub title<a class="headerlink" href="#subsub-title" title="Permalink to this headline"></a></h3>
1919
<p>This is a H3 title.</p>
20+
21+
<!-- Figure with permalink and caption -->
22+
<div class="figure align-center" id="id1">
23+
<a class="reference internal image-reference" href="_images/search-analytics-demo.png">
24+
<img alt="Search analytics demo" src="_images/figure.png" style="width: 50%;">
25+
</a>
26+
<p class="caption">
27+
<span class="caption-number">Fig. 4 </span><span class="caption-text">I'm a figure!</span>
28+
<a class="headerlink" href="#id1" title="Permalink to this image"></a>
29+
</p>
30+
</div>
2031
</div>
2132
</div>
2233

readthedocs/search/tests/data/sphinx/out/page.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"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)"
2929
},
3030
{
31-
"content": "This is a H3 title.",
31+
"content": "This is a H3 title. Fig. 4 I'm a figure!",
3232
"id": "subsub-title",
3333
"title": "Subsub title"
3434
}

0 commit comments

Comments
 (0)