mirror of
https://github.com/cotes2020/jekyll-theme-chirpy.git
synced 2025-10-20 09:43:36 +00:00
fix(search): restore full-text search for posts with description (#2557)
This commit is contained in:
parent
b3d7db3cda
commit
604528e3ce
@ -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 -}}
|
39
_includes/post-summary.html
Normal file
39
_includes/post-summary.html
Normal 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 -%}
|
@ -82,7 +82,7 @@
|
||||
{% include datetime.html date=post.date lang=include.lang %}
|
||||
<h4 class="pt-0 my-2">{{ post.title }}</h4>
|
||||
<div class="text-muted">
|
||||
<p>{% include post-description.html %}</p>
|
||||
<p>{% include post-summary.html %}</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
@ -78,7 +78,7 @@ refactor: true
|
||||
<h1 class="card-title my-2 mt-md-0">{{ post.title }}</h1>
|
||||
|
||||
<div class="card-text content mt-0 mb-3">
|
||||
<p>{% include post-description.html %}</p>
|
||||
<p>{% include post-summary.html %}</p>
|
||||
</div>
|
||||
|
||||
<div class="post-meta flex-grow-1 d-flex align-items-end">
|
||||
|
@ -45,7 +45,7 @@ permalink: /feed.xml
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<summary>{% include post-description.html max_length=400 %}</summary>
|
||||
<summary>{% include post-summary.html max_length=400 %}</summary>
|
||||
|
||||
</entry>
|
||||
{% endfor %}
|
||||
|
@ -11,7 +11,8 @@ swcache: true
|
||||
"categories": {{ post.categories | join: ', ' | jsonify }},
|
||||
"tags": {{ post.tags | join: ', ' | 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 %}
|
||||
{% endfor %}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user