From 83126ba51f74733d25f9a307b4c76bf874e69a20 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 | 11 ++++++++++- _includes/search-loader.html | 2 +- assets/js/data/search.json | 8 ++++---- 4 files changed, 15 insertions(+), 16 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..e0d82889cd8 100644
--- a/_includes/post-description.html
+++ b/_includes/post-description.html
@@ -8,7 +8,16 @@
 {%- if post.description -%}
   {{- post.description -}}
 {%- else -%}
-  {%- include no-linenos.html content=post.content -%}
+  {% 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 -}}
 {%- 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..820ce3e0694 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 | newline_to_br | replace: '
', ' ' | strip_newlines }}" }{% unless forloop.last %},{% endunless %} {% endfor %} ]