Skip to content

Commit a72b662

Browse files
authored
Search: link to main project in subproject results (#7880)
Closes #7487
1 parent 4f7a210 commit a72b662

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

readthedocs/core/static-src/core/js/doc-embed/search.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ function attach_elastic_search_query_sphinx(data) {
7070
}
7171

7272
var link = result.path + "?highlight=" + $.urlencode(query);
73+
// If we aren't on the main domain of the subproject, link to it.
74+
// TODO: we should always redirect to the main domain instead.
75+
if (result.path.startsWith('/projects/') && !window.location.href.startsWith(result.domain)) {
76+
link = result.domain + link;
77+
}
7378

7479
var item = $('<a>', {'href': link});
7580

@@ -289,9 +294,16 @@ function attach_elastic_search_query_mkdocs(data) {
289294
var result = results[i];
290295
var blocks = result.blocks;
291296

297+
var link = result.path;
298+
// If we aren't on the main domain of the subproject, link to it.
299+
// TODO: we should always redirect to the main domain instead.
300+
if (result.path.startsWith('/projects/') && !window.location.href.startsWith(result.domain)) {
301+
link = result.domain + link;
302+
}
303+
292304
var item = $('<article>');
293305
item.append(
294-
$('<h3>').append($('<a>', {'href': result.path, 'text': result.title}))
306+
$('<h3>').append($('<a>', {'href': link, 'text': result.title}))
295307
);
296308

297309
if (result.project !== project) {
@@ -303,7 +315,7 @@ function attach_elastic_search_query_mkdocs(data) {
303315
var section = blocks[j];
304316

305317
if (section.type === 'section') {
306-
var section_link = result.path + '#' + section.id;
318+
var section_link = link + '#' + section.id;
307319
var section_title = section.title;
308320
var section_content = section.content;
309321
if (section_content.length > MAX_SUBSTRING_LIMIT) {

0 commit comments

Comments
 (0)