Skip to content

Commit 7bcc1a7

Browse files
authored
fix(search): restore full-text search for posts with description (cotes2020#2557)
1 parent 7fa0638 commit 7bcc1a7

File tree

6 files changed

+44
-34
lines changed

6 files changed

+44
-34
lines changed

_includes/post-description.html

Lines changed: 0 additions & 30 deletions
This file was deleted.

_includes/post-summary.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{%- comment -%}
2+
Get the post's description or body content.
3+
4+
Arguments:
5+
full_text: If true, return the full content. Default is false.
6+
max_length: The maximum length of the returned content. Default is 200.
7+
{%- endcomment -%}
8+
9+
{%- if post.description and include.full_text != true -%}
10+
{{- post.description -}}
11+
{%- else -%}
12+
{%- comment -%} Remove the line numbers from the code snippet. {%- endcomment -%}
13+
14+
{%- assign content = post.content -%}
15+
16+
{%- if content contains '<td class="rouge-gutter gl"><pre class="lineno">' -%}
17+
{%- assign content = content
18+
| replace: '<td class="rouge-gutter gl"><pre class="lineno">',
19+
'<!-- <td class="rouge-gutter gl"><pre class="lineno">'
20+
-%}
21+
{%- assign content = content | replace: '</td><td class="rouge-code">', '</td> --><td class="rouge-code">' -%}
22+
{%- endif -%}
23+
24+
{%- assign content = content
25+
| markdownify
26+
| strip_html
27+
| newline_to_br
28+
| replace: '<br />', ' '
29+
| strip_newlines
30+
| strip
31+
-%}
32+
33+
{%- unless include.full_text -%}
34+
{%- assign max_length = include.max_length | default: 200 -%}
35+
{%- assign content = content | truncate: max_length -%}
36+
{%- endunless -%}
37+
38+
{{- content -}}
39+
{%- endif -%}

_includes/related-posts.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ <h3 class="mb-4" id="related-label">
8282
{% include datetime.html date=post.date lang=include.lang %}
8383
<h4 class="pt-0 my-2">{{ post.title }}</h4>
8484
<div class="text-muted">
85-
<p>{% include post-description.html %}</p>
85+
<p>{% include post-summary.html %}</p>
8686
</div>
8787
</div>
8888
</a>

_layouts/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<h1 class="card-title my-2 mt-md-0">{{ post.title }}</h1>
7979

8080
<div class="card-text content mt-0 mb-3">
81-
<p>{% include post-description.html %}</p>
81+
<p>{% include post-summary.html %}</p>
8282
</div>
8383

8484
<div class="post-meta flex-grow-1 d-flex align-items-end">

assets/feed.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ permalink: /feed.xml
4545
{% endfor %}
4646
{% endif %}
4747

48-
<summary>{% include post-description.html max_length=400 %}</summary>
48+
<summary>{% include post-summary.html max_length=400 %}</summary>
4949

5050
</entry>
5151
{% endfor %}

assets/js/data/search.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ swcache: true
1111
"categories": {{ post.categories | join: ', ' | jsonify }},
1212
"tags": {{ post.tags | join: ', ' | jsonify }},
1313
"date": {{ post.date | jsonify }},
14-
"content": {% include post-description.html json=true %}
14+
{% capture content -%}{% include post-summary.html full_text=true %}{%- endcapture -%}
15+
"content": {{ content | jsonify }}
1516
}{% unless forloop.last %},{% endunless %}
1617
{% endfor %}
1718
]

0 commit comments

Comments
 (0)