Skip to content

Commit

Permalink
fix(search): avoid missing spaces between paragraphs in search results (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
cotes2020 committed Jan 20, 2025
1 parent e44c048 commit 0eb7efa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
10 changes: 0 additions & 10 deletions _includes/no-linenos.html

This file was deleted.

13 changes: 11 additions & 2 deletions _includes/post-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
{%- if post.description -%}
{{- post.description -}}
{%- else -%}
{%- include no-linenos.html content=post.content -%}
{{- content | markdownify | strip_html -}}
{% comment %}
Remove the line number of the code snippet.
{% endcomment %}
{% assign content = post.content %}

{% if content contains '<td class="rouge-gutter gl"><pre class="lineno">' %}
{% assign content = content | replace: '<td class="rouge-gutter gl"><pre class="lineno">', '<!-- <td class="rouge-gutter gl"><pre class="lineno">'%}
{% assign content = content | replace: '</td><td class="rouge-code">', '</td> --><td class="rouge-code">' %}
{% endif %}

{{- content | markdownify | strip_html | newline_to_br | replace: '<br />', ' ' | strip_newlines -}}
{%- endif -%}
{%- endcapture -%}

Expand Down
2 changes: 1 addition & 1 deletion _includes/search-loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2><a href="{url}">{title}</a></h2>
{tags}
</div>
</header>
<p>{snippet}</p>
<p>{content}</p>
</article>
{% endcapture %}

Expand Down
8 changes: 4 additions & 4 deletions assets/js/data/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ swcache: true

[
{% for post in site.posts %}
{%- capture description -%}
{% include post-description.html %}
{%- endcapture -%}
{
"title": {{ post.title | jsonify }},
"url": {{ post.url | relative_url | jsonify }},
"categories": {{ post.categories | join: ', ' | jsonify }},
"tags": {{ post.tags | join: ', ' | jsonify }},
"date": "{{ post.date }}",
{% include no-linenos.html content=post.content %}
{% assign _content = content | strip_html | strip_newlines %}
"snippet": {{ _content | truncate: 200 | jsonify }},
"content": {{ _content | jsonify }}
"content": "{{ description }}"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
]

0 comments on commit 0eb7efa

Please sign in to comment.