Skip to content

Fix spacing between the results and add highlight url param #5932

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 6 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 8 additions & 4 deletions readthedocs/core/static-src/core/js/doc-embed/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ function attach_elastic_search_query(data) {
}

// Creating the result from elements
var link = doc.link + DOCUMENTATION_OPTIONS.FILE_SUFFIX;
var highlight_link = link + "?highlight=" + $.urlencode(query);
var link = doc.link + DOCUMENTATION_OPTIONS.FILE_SUFFIX + "?highlight=" + $.urlencode(query);

var item = $('<a>', {'href': highlight_link});
var item = $('<a>', {'href': link});
item.html(title);
item.find('em').addClass('highlighted');
list_item.append(item);
Expand Down Expand Up @@ -170,7 +169,12 @@ function attach_elastic_search_query(data) {

contents.find('em').addClass('highlighted');
list_item.append(contents);
list_item.append($("<br>"));

// Create some spacing between the results.
// Also, don't add this spacing in the last hit.
if (j !== inner_hits.length - 1) {
list_item.append($("<div style='margin: 10px 0'></div>"));
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't like inline styles here, but it might be necessary since it needs to work across all themes. I feel like we need to make this a classname and have CSS though to make it be user-configurable.

Copy link
Member

Choose a reason for hiding this comment

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

We could include a CSS class addition here, which we add to all docs: https://assets.readthedocs.org/static/css/readthedocs-doc-embed.css

Copy link
Member Author

Choose a reason for hiding this comment

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

@ericholscher
I have changed it use a css file and have added css styles in readthedocs-doc-embed.css.

}

Search.output.append(list_item);
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/core/static/core/js/readthedocs-doc-embed.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions readthedocs/templates/search/elastic_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ <h3>
{% for inner_hit in result.meta.inner_hits %}
{% if inner_hit.type == 'domains' %}
<p>
<a href="{% doc_url result.project|get_project result.version inner_hit.source.doc_name %}#{{ inner_hit.source.anchor }}">
<a href="{% doc_url result.project|get_project result.version inner_hit.source.doc_name %}?highlight= {{ query }}#{{ inner_hit.source.anchor }}">

{% if inner_hit.source.display_name|length >= 1 %}
({{ inner_hit.source.role_name }}) {{ inner_hit.source.display_name}}
Expand All @@ -207,7 +207,7 @@ <h3>

{% elif inner_hit.type == 'sections' %}
<p>
<a href="{% doc_url result.project|get_project result.version result.full_path %}#{{ inner_hit.source.id }}">
<a href="{% doc_url result.project|get_project result.version result.full_path %}?highlight={{ query }}#{{ inner_hit.source.id }}">
{% if inner_hit.highlight|get_key_or_none:"sections.title" %}
{% with section_title=inner_hit.highlight|get_key_or_none:"sections.title" %}
{{ section_title.0|safe }}
Expand Down