From 604528e3ce11ec0278e83f41105ed5949362bb54 Mon Sep 17 00:00:00 2001 From: Cotes <11371340+cotes2020@users.noreply.github.com> Date: Mon, 20 Oct 2025 02:24:40 +0800 Subject: [PATCH] fix(search): restore full-text search for posts with description (#2557) --- _includes/post-description.html | 30 ------------------------- _includes/post-summary.html | 39 +++++++++++++++++++++++++++++++++ _includes/related-posts.html | 2 +- _layouts/home.html | 2 +- assets/feed.xml | 2 +- assets/js/data/search.json | 3 ++- 6 files changed, 44 insertions(+), 34 deletions(-) delete mode 100644 _includes/post-description.html create mode 100644 _includes/post-summary.html diff --git a/_includes/post-description.html b/_includes/post-description.html deleted file mode 100644 index 48bb03b..0000000 --- a/_includes/post-description.html +++ /dev/null @@ -1,30 +0,0 @@ -{%- comment -%} - Get post description or generate it from the post content. -{%- endcomment -%} - -{%- capture description -%} - {%- if post.description -%} - {{- post.description -}} - {%- else -%} - {% comment %} - Remove the line number of the code snippet. - {% endcomment %} - {%- assign content = post.content -%} - - {%- if content contains '
' -%}
- {%- assign content = content | replace: '', '' -%}
- {%- endif -%}
-
- {{- content | strip_html | newline_to_br | replace: '
', ' ' | strip_newlines -}}
- {%- endif -%}
-{%- endcapture -%}
-
-{%- if include.json -%}
- {%- assign description = description | jsonify -%}
-{%- else -%}
- {%- assign max_length = include.max_length | default: 200 -%}
- {%- assign description = description | strip | truncate: max_length -%}
-{%- endif -%}
-
-{{- description -}}
diff --git a/_includes/post-summary.html b/_includes/post-summary.html
new file mode 100644
index 0000000..c9314fc
--- /dev/null
+++ b/_includes/post-summary.html
@@ -0,0 +1,39 @@
+{%- comment -%}
+ Get the post's description or body content.
+
+ Arguments:
+ full_text: If true, return the full content. Default is false.
+ max_length: The maximum length of the returned content. Default is 200.
+{%- endcomment -%}
+
+{%- if post.description and include.full_text != true -%}
+ {{- post.description -}}
+{%- else -%}
+ {%- comment -%} Remove the line numbers from the code snippet. {%- endcomment -%}
+
+ {%- assign content = post.content -%}
+
+ {%- if content contains ' ' -%}
+ {%- assign content = content
+ | replace: '',
+ '' -%}
+ {%- endif -%}
+
+ {%- assign content = content
+ | markdownify
+ | strip_html
+ | newline_to_br
+ | replace: '
', ' '
+ | strip_newlines
+ | strip
+ -%}
+
+ {%- unless include.full_text -%}
+ {%- assign max_length = include.max_length | default: 200 -%}
+ {%- assign content = content | truncate: max_length -%}
+ {%- endunless -%}
+
+ {{- content -}}
+{%- endif -%}
diff --git a/_includes/related-posts.html b/_includes/related-posts.html
index 37a295b..4b4f808 100644
--- a/_includes/related-posts.html
+++ b/_includes/related-posts.html
@@ -82,7 +82,7 @@
{% include datetime.html date=post.date lang=include.lang %}
{{ post.title }}
- {% include post-description.html %}
+ {% include post-summary.html %}
diff --git a/_layouts/home.html b/_layouts/home.html
index 66a1201..cb9ab24 100644
--- a/_layouts/home.html
+++ b/_layouts/home.html
@@ -78,7 +78,7 @@ refactor: true
{{ post.title }}
- {% include post-description.html %}
+ {% include post-summary.html %}