diff --git a/_includes/post-description.html b/_includes/post-description.html index c00e516..48bb03b 100644 --- a/_includes/post-description.html +++ b/_includes/post-description.html @@ -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 '
' %}
- {% assign content = content | replace: '', '' %}
- {% endif %}
+ {%- if content contains ' ' -%}
+ {%- assign content = content | replace: '', '' -%}
+ {%- endif -%}
- {{- content | markdownify | strip_html | newline_to_br | replace: '
', ' ' | strip_newlines -}}
-{%- endif -%}
+ {{- content | strip_html | newline_to_br | replace: '
', ' ' | 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 -}}
diff --git a/assets/js/data/search.json b/assets/js/data/search.json
index 32bcff9..5003e51 100644
--- a/assets/js/data/search.json
+++ b/assets/js/data/search.json
@@ -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 %}
]