1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-10-20 17:53:45 +00:00

fix(search): restore full-text search for posts with description (#2557)

This commit is contained in:
Cotes 2025-10-20 02:24:40 +08:00 committed by GitHub
parent b3d7db3cda
commit 604528e3ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 44 additions and 34 deletions

View File

@ -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 '<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 | strip_html | newline_to_br | replace: '<br />', ' ' | 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 -}}

View File

@ -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 '<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 -%}
{%- assign content = content
| markdownify
| strip_html
| newline_to_br
| replace: '<br />', ' '
| strip_newlines
| strip
-%}
{%- unless include.full_text -%}
{%- assign max_length = include.max_length | default: 200 -%}
{%- assign content = content | truncate: max_length -%}
{%- endunless -%}
{{- content -}}
{%- endif -%}

View File

@ -82,7 +82,7 @@
{% include datetime.html date=post.date lang=include.lang %} {% include datetime.html date=post.date lang=include.lang %}
<h4 class="pt-0 my-2">{{ post.title }}</h4> <h4 class="pt-0 my-2">{{ post.title }}</h4>
<div class="text-muted"> <div class="text-muted">
<p>{% include post-description.html %}</p> <p>{% include post-summary.html %}</p>
</div> </div>
</div> </div>
</a> </a>

View File

@ -78,7 +78,7 @@ refactor: true
<h1 class="card-title my-2 mt-md-0">{{ post.title }}</h1> <h1 class="card-title my-2 mt-md-0">{{ post.title }}</h1>
<div class="card-text content mt-0 mb-3"> <div class="card-text content mt-0 mb-3">
<p>{% include post-description.html %}</p> <p>{% include post-summary.html %}</p>
</div> </div>
<div class="post-meta flex-grow-1 d-flex align-items-end"> <div class="post-meta flex-grow-1 d-flex align-items-end">

View File

@ -45,7 +45,7 @@ permalink: /feed.xml
{% endfor %} {% endfor %}
{% endif %} {% endif %}
<summary>{% include post-description.html max_length=400 %}</summary> <summary>{% include post-summary.html max_length=400 %}</summary>
</entry> </entry>
{% endfor %} {% endfor %}

View File

@ -11,7 +11,8 @@ swcache: true
"categories": {{ post.categories | join: ', ' | jsonify }}, "categories": {{ post.categories | join: ', ' | jsonify }},
"tags": {{ post.tags | join: ', ' | jsonify }}, "tags": {{ post.tags | join: ', ' | jsonify }},
"date": {{ post.date | jsonify }}, "date": {{ post.date | jsonify }},
"content": {% include post-description.html json=true %} {% capture content -%}{% include post-summary.html full_text=true %}{%- endcapture -%}
"content": {{ content | jsonify }}
}{% unless forloop.last %},{% endunless %} }{% unless forloop.last %},{% endunless %}
{% endfor %} {% endfor %}
] ]