1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2025-08-06 16:31:08 +00:00

fix: escape special JSON characters in search results (#2481)

Also restore full-text search
This commit is contained in:
Cotes Chung 2025-07-26 20:22:30 +08:00 committed by GitHub
parent 53770e4923
commit 7615d72e93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 21 deletions

View File

@ -2,24 +2,29 @@
Get post description or generate it from the post content.
{%- endcomment -%}
{%- assign max_length = include.max_length | default: 200 -%}
{%- capture description -%}
{%- if post.description -%}
{{- post.description -}}
{%- else -%}
{% comment %}
Remove the line number of the code snippet.
{% endcomment %}
{% assign content = post.content %}
{%- 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 %}
{%- 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 -%}
{{- content | strip_html | newline_to_br | replace: '<br />', ' ' | strip_newlines -}}
{%- endif -%}
{%- endcapture -%}
{{- description | strip | truncate: max_length | escape -}}
{%- 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

@ -5,16 +5,13 @@ 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 }}",
"content": "{{ description }}"
"date": {{ post.date | jsonify }},
"content": {% include post-description.html json=true %}
}{% unless forloop.last %},{% endunless %}
{% endfor %}
]