From 0eb7efa7f53508bf6b48eb9d773d5c5047c3c525 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 20 Jan 2025 21:15:51 +0800 Subject: [PATCH] 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 --- _includes/no-linenos.html | 10 ---------- _includes/post-description.html | 13 +++++++++++-- _includes/search-loader.html | 2 +- assets/js/data/search.json | 8 ++++---- 4 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 _includes/no-linenos.html diff --git a/_includes/no-linenos.html b/_includes/no-linenos.html deleted file mode 100644 index 85006933708..00000000000 --- a/_includes/no-linenos.html +++ /dev/null @@ -1,10 +0,0 @@ -{% comment %} - Remove the line number of the code snippet. -{% endcomment %} - -{% assign content = include.content %} - -{% if content contains '
' %} - {% assign content = content | replace: ' ', '' %} -{% endif %} diff --git a/_includes/post-description.html b/_includes/post-description.html index 6c400360bf3..c00e516533e 100644 --- a/_includes/post-description.html +++ b/_includes/post-description.html @@ -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 ' ' %} + {% assign content = content | replace: ' ', '' %} + {% endif %} + + {{- content | markdownify | strip_html | newline_to_br | replace: '
', ' ' | strip_newlines -}} {%- endif -%} {%- endcapture -%} diff --git a/_includes/search-loader.html b/_includes/search-loader.html index 7fd065d8f59..5a43fba8351 100644 --- a/_includes/search-loader.html +++ b/_includes/search-loader.html @@ -12,7 +12,7 @@{title}
{tags} -{snippet}
+{content}
{% endcapture %} diff --git a/assets/js/data/search.json b/assets/js/data/search.json index 2601ed076bd..32bcff9b0c5 100644 --- a/assets/js/data/search.json +++ b/assets/js/data/search.json @@ -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 %} ]