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
This commit is contained in:
Cotes Chung 2025-01-20 21:15:51 +08:00
parent e44c048aef
commit 0eb7efa7f5
No known key found for this signature in database
GPG key ID: 0D9E54843167A808
4 changed files with 16 additions and 17 deletions

View file

@ -1,10 +0,0 @@
{% comment %}
Remove the line number of the code snippet.
{% endcomment %}
{% assign content = include.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 %}

View file

@ -8,8 +8,17 @@
{%- if post.description -%}
{{- post.description -}}
{%- else -%}
{%- include no-linenos.html content=post.content -%}
{{- content | markdownify | strip_html -}}
{% 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 | markdownify | strip_html | newline_to_br | replace: '<br />', ' ' | strip_newlines -}}
{%- endif -%}
{%- endcapture -%}

View file

@ -12,7 +12,7 @@
{tags}
</div>
</header>
<p>{snippet}</p>
<p>{content}</p>
</article>
{% endcapture %}

View file

@ -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 }}"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
]