Skip to content

Search: link to main project in subproject results #7880

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
Feb 22, 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
16 changes: 14 additions & 2 deletions readthedocs/core/static-src/core/js/doc-embed/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ function attach_elastic_search_query_sphinx(data) {
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think on .com we allow users to customize this path, so we probably need something smarter here in the future, but this should work for 99% of users for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think redirecting to the main project should fix all this, but that's a bigger change in proxito

link = result.domain + link;
}

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

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

var link = result.path;
// If we aren't on the main domain of the subproject, link to it.
// TODO: we should always redirect to the main domain instead.
if (result.path.startsWith('/projects/') && !window.location.href.startsWith(result.domain)) {
link = result.domain + link;
}

var item = $('<article>');
item.append(
$('<h3>').append($('<a>', {'href': result.path, 'text': result.title}))
$('<h3>').append($('<a>', {'href': link, 'text': result.title}))
);

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

if (section.type === 'section') {
var section_link = result.path + '#' + section.id;
var section_link = link + '#' + section.id;
var section_title = section.title;
var section_content = section.content;
if (section_content.length > MAX_SUBSTRING_LIMIT) {
Expand Down
Loading