Skip to content

Commit 0eb7efa

Browse files
committed
fix(search): avoid missing spaces between paragraphs in search results (#2199)
- Use a common post-snippet for search results to avoid line break issues - Reduce Jekyll include files to speed up the build - Remove outdated key from search.json
1 parent e44c048 commit 0eb7efa

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

_includes/no-linenos.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

_includes/post-description.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@
88
{%- if post.description -%}
99
{{- post.description -}}
1010
{%- else -%}
11-
{%- include no-linenos.html content=post.content -%}
12-
{{- content | markdownify | strip_html -}}
11+
{% comment %}
12+
Remove the line number of the code snippet.
13+
{% endcomment %}
14+
{% assign content = post.content %}
15+
16+
{% if content contains '<td class="rouge-gutter gl"><pre class="lineno">' %}
17+
{% assign content = content | replace: '<td class="rouge-gutter gl"><pre class="lineno">', '<!-- <td class="rouge-gutter gl"><pre class="lineno">'%}
18+
{% assign content = content | replace: '</td><td class="rouge-code">', '</td> --><td class="rouge-code">' %}
19+
{% endif %}
20+
21+
{{- content | markdownify | strip_html | newline_to_br | replace: '<br />', ' ' | strip_newlines -}}
1322
{%- endif -%}
1423
{%- endcapture -%}
1524

_includes/search-loader.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h2><a href="{url}">{title}</a></h2>
1212
{tags}
1313
</div>
1414
</header>
15-
<p>{snippet}</p>
15+
<p>{content}</p>
1616
</article>
1717
{% endcapture %}
1818

assets/js/data/search.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ swcache: true
55

66
[
77
{% for post in site.posts %}
8+
{%- capture description -%}
9+
{% include post-description.html %}
10+
{%- endcapture -%}
811
{
912
"title": {{ post.title | jsonify }},
1013
"url": {{ post.url | relative_url | jsonify }},
1114
"categories": {{ post.categories | join: ', ' | jsonify }},
1215
"tags": {{ post.tags | join: ', ' | jsonify }},
1316
"date": "{{ post.date }}",
14-
{% include no-linenos.html content=post.content %}
15-
{% assign _content = content | strip_html | strip_newlines %}
16-
"snippet": {{ _content | truncate: 200 | jsonify }},
17-
"content": {{ _content | jsonify }}
17+
"content": "{{ description }}"
1818
}{% unless forloop.last %},{% endunless %}
1919
{% endfor %}
2020
]

0 commit comments

Comments
 (0)